Click here to Skip to main content
14,635,966 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
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
   
v2
Rate this:
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.
   
v2

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




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