Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server
Table Name UserInfromation
 
Column Name Data Type Allow Nulls
UserId Int (Set Identity=true) No
UserName varchar(50) Yes
Location Varchar(50) Yes
 

Table Name OrderInformation
 
Column Name Data Type Allow Nulls
OrderId Int No
OrderNo int Yes
UserId int NO
 

UserInfromation table data as follows;
UserId UserName Location
1 Suresh Chennai
2 Prasant Chennai
3 Madhavi Delhi
4 Mahesh Mumbai
 
OrderInformation table data as follows;
OrderId OrderNo UserId
1 543 1
2 213 2
3 977 3
4 323 3
5 998 1
 

I wan the output as follows
 
UserId UserName Location OrderNo
1 Suresh Chennai 543
1 Suresh Chennai 998
2 Prasant Chennai 213
3 Madhavi Delhi 977
3 Madhavi Delhi 323
 

For the above query how to write the query in sqlserver.please hlep me i am new to write the query using joins.
Posted 23-Nov-12 6:30am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Here you go.
SELECT u.UserId, u.UserName, u.Location, o.OrderNo
From UserInfromation u INNER JOIN OrderInformation o
ON u.UserId = o.UserId;
 
Time for you to begin learning SQL JOINs.
http://www.w3schools.com/sql/sql_join.asp
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

select UserId, UserName, Location, OrderNo from  UserInfromation,OrderInfromation
where  UserInfromation.UserId= OrderInfromation.Userid
 
Dude,
 
i guess you are a beginner in Sql server, so first learn the basics through any book.
 
--Prathap.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 480
1 Maciej Los 290
2 Richard MacCutchan 225
3 BillWoodruff 185
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,764
1 Sergey Alexandrovich Kryukov 7,437
2 DamithSL 5,639
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411028.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100