|
|
#1 |
|
Hyperactive Member
Join Date: May 01
Location: Köln
Posts: 385
![]() |
Hi guys,
I need help with a querry. (Access DB 2003) I have 2 Tables Table1.....Field =========== ..............GuestID ..............GuestName The Field GuestID is Unique and starts either with the letter 'F' or 'P' depending if the guest is a private person or a company Table2.....Field =========== .............BookingID .............GuestID1 .............GuestID2 .............Arrival .............Departure The Fields GuestID1 and GuestID2 are the link to the Table1.GuestID GuestID1 has alltimes a value GuestID2 could have an entry. This is depending if on the Invoice has the private and company name on it. So what I need is a querry which solves the following Result should look like this Table2.BookingID Table1.GuestName - Related to Table2.GuestID1 Table1.GuestName - Related to Table2.GuestID2 (keep in mind this ...................................................................field could be NULL) the rest I think i can figure out . hopefully Hope you can help me with this. many thx in advance and a peacefull xmas season to you all. |
|
|
|
|
|
#2 |
|
Just Married
Join Date: Mar 06
Location: Udaipur,Rajasthan(INDIA)
Posts: 3,742
![]() ![]() |
Design the query using Access' query designer and test.
|
|
|
|
|
|
#3 | |
|
Hyperactive Member
Join Date: May 01
Location: Köln
Posts: 385
![]() |
Re: Need help with a querry
Quote:
so back to pure SQL. Anyone else has a solution for this? Last edited by Bongo; Dec 23rd, 2006 at 08:05 AM. |
|
|
|
|
|
|
#4 |
|
Hyperactive Member
Join Date: May 01
Location: Köln
Posts: 385
![]() |
Re: Need help with a querry
I came up sofare with this querry
SELECT Table2.BookingID, T1.Name, T2.Name, Arraival, Derparture FROM (Table2 INNER JOIN Table1 AS T1 ON Table2.GuestID1 = T1.GuestID) INNER JOIN Table1 AS T2 ON Table2.GuestID2 = T2.GuestID I only get records But i still do not get records where on Table2.GuestID2 the Value = NULL |
|
|
|
|
|
#5 |
|
Just Married
Join Date: Mar 06
Location: Udaipur,Rajasthan(INDIA)
Posts: 3,742
![]() ![]() |
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
|
|
|
|
|
|
#6 |
|
MS SQL Powerposter
Join Date: Mar 04
Location: CT
Posts: 12,269
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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
__________________
*** Read the sticky in the DB forum about how to get your question answered quickly!! *** Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post". Some Informative Links: [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ] [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ VB.Net Database Class ] [ Loading Pictures from DB ] MS MVP 2006, 2007, 2008 |
|
|
|
|
|
#7 | |
|
Hyperactive Member
Join Date: May 01
Location: Köln
Posts: 385
![]() |
Re: Need help with a querry
Quote:
@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? |
|
|
|
|
|
|
#8 |
|
Hyperactive Member
Join Date: May 01
Location: Köln
Posts: 385
![]() |
Re: Need help with a querry
Its Working Many thanks to you guys and to all a merry xmas and a good 2007 |
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|