|
-
Dec 23rd, 2006, 08:31 AM
#1
Re: Need help with a querry
Code:
SELECT Table2.BookingID, T1.Name, T2.Name, Arraival, Derparture
FROM (Table2 LEFT JOIN Table1 AS T1 ON Table2.GuestID1 = T1.GuestID) LEFT JOIN Table1 AS T2 ON Table2.GuestID2 = T2.GuestID
Use Left Join
-
Dec 23rd, 2006, 08:48 AM
#2
Re: Need help with a querry
This should work (use ALIAS syntax)
Code:
Select TA.BookingId
,TA.GuestID1
,T1.GuestName as GuestName1
,TA.GuestID2
,T2.GuestName as GuestName2
,TA.Arrival
,TA.Departure
From Table2 TA
Left Join Table1 T1 on T1.GuestId=TA.GuestID1
Left Join Table1 T2 on T2.GuestId=TA.GuestID2
This would work in MS SQL - you can join the same table as many times as you want as long as you give them a unique alias name.
-
Dec 23rd, 2006, 09:27 AM
#3
Thread Starter
Hyperactive Member
Re: Need help with a querry
 Originally Posted by szlamany
This should work (use ALIAS syntax)
Code:
Select TA.BookingId
,TA.GuestID1
,T1.GuestName as GuestName1
,TA.GuestID2
,T2.GuestName as GuestName2
,TA.Arrival
,TA.Departure
From Table2 TA
Left Join Table1 T1 on T1.GuestId=TA.GuestID1
Left Join Table1 T2 on T2.GuestId=TA.GuestID2
This would work in MS SQL - you can join the same table as many times as you want as long as you give them a unique alias name.
@shakti5385 - thx
@szlamany
thx as well but I still get an error which says roughly translatet into english
Syntaxerror (missing operator) on query 'T1.GuestID=TA.GuestID1 ON (Left Join Table1 T2 on T2.GuestId=TA.GuestID2)'
What else I am doing wrong?
-
Dec 23rd, 2006, 10:09 AM
#4
Thread Starter
Hyperactive Member
Re: Need help with a querry
Its Working
Many thanks to you guys and to all a merry xmas and a good 2007
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|