Sql server join
-
Sunday, March 17, 2013 3:41 AM
hi,
i had three tables, they are NonReg,Reg,Bookings
in Booking table like thisBookingID Bookingdate UID isReg
1 12/03/2012 10 0
2 11/03/2012 10 1
for NonReg Table like thisUID UNAME
10 bavaji
for Reg Table like this
UID UNAME
10 basha
how to perfom the join for these three tables
i.e. when isReg is 0 then perform the join to Booking table and NonReg Tables
and when isReg is 1 then perform the join to Booking table and Reg Tables
All Replies
-
Sunday, March 17, 2013 3:47 AMModerator
The simplest way
select B.*, NR.UName from Booking B INNER JOIN NonReq NR ON B.UID = NR.UID WHERE B.isReq = 0 UNION ALL select B.*, R.UName from Booking B INNER JOIN Req R ON B.UID = R.UID WHERE B.isReq = 1
For every expert, there is an equal and opposite expert. - Becker's Law
My blog- Proposed As Answer by Sarat Babu (SS) Sunday, March 17, 2013 3:58 AM
- Marked As Answer by Allen Li - MSFTModerator Tuesday, March 19, 2013 1:04 AM
-
Sunday, March 17, 2013 4:55 AM
Thank you, :) :) :)

