query in a query

poporacer

Registered User.
Local time
Yesterday, 23:57
Joined
Aug 30, 2007
Messages
136
I have two tables (tblRoster and tblAKA) tblRoster has the specifics on each person (ID#(unique identifier) Name, Address, Phone) tblAKA has the ID# and nicknames, sometimes more than one nickname for a person. I need a query that will join the two tables BUT I only want one entry for each person.

Here is an example of what I am trying to do:

tblRoster:
ID Name Address Phone
1 Betty 123 St. 555-123-1234
2 Sam 321 W. 555-987-1234
3 Tom 456 S. 555-456-9876

tblAKA:
ID Nick
1 Betty Boop
2 Shorty
1 Scary

And I want to get the following results:
ID Name Address Phone Nick
1 Betty 123 St. 555-123-1234 Betty Boop
2 Sam 321 W. 555-987-1234 Shorty
3 Tom 456 S. 555-456-9876

I tried a Left Join and tried to use the DISTINCT property on the ID but still got duplicates:

ID Name Address Phone Nick
1 Betty 123 St. 555-123-1234 Betty Boop
1 Betty 123 St. 555-123-1234 Scary
2 Sam 321 W. 555-987-1234 Shorty
3 Tom 456 S. 555-456-9876

I also tried something but didn't work but seemed close:
SELECT ID, Name, Address, Phone, tblAKA.Nick
FROM tblRoster
LEFT JOIN
(SELECT DISTINCT tblAKA.ID, tblAKA.Nick FROM tblAKA) on tblRoster.ID = tblAKA.ID

Any Ideas???
 
Popo,

Code:
Select A.ID,
       A.Name,
       A.Address,
       A.Phone,
       B.Nick
From   tblRoster As A Left Join tblADA On
         A.ID = B.ID
Order By A.ID

Wayne
 
Thanks a bunch.....I got it working with your help!!!
 

Users who are viewing this thread

Back
Top Bottom