Click here to Skip to main content
12,886,364 members (41,668 online)
Rate this:
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 5:30am
Rate this: bad
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

select UserId, UserName, Location, OrderNo from  UserInfromation,OrderInfromation
where  UserInfromation.UserId= OrderInfromation.Userid


i guess you are a beginner in Sql server, so first learn the basics through any book.


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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2017
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