Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

Here you go.
SQL
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
 
Share this answer
 
v2
SQL
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.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900