Link to home
Start Free TrialLog in
Avatar of cartch2008
cartch2008

asked on

T-SQL Select Query Question

I have 2 tables.  tblContacts and tblAddresses.  There is a 1 to many relationship between tblContacts and tblAddresses = a contact can have more than 1 address, and an address can only belong to 1 contact.

Here is what I want to do in pseudo code.

select tblcontacts.lastname,all cities found in tbladdresses for the contact seperated by commas
from tblcontacts, tbladdresses
where tblcontacts.contactid = tbladdresses.addressid

ie:
Jackson   New York,Chicago,LA
Smith        Boston,London,Toronto,LA

I dont' want:
Jackson   New York
Jackson   Chicago
Jackson    LA
Smith         Boston
Smith         London
Smith         Toronto
Smith         LA

Is it possible to do this in 1 query somehow?  If so, how?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cartch2008
cartch2008

ASKER

brilliant...all these years developing and doing it in 2 separate resource hogging queries, and I didn't know you could do this! thanks