troubleshooting Question

T-SQL Select Query Question

Avatar of cartch2008
cartch2008 asked on
Microsoft SQL Server 2008SQL
4 Comments3 Solutions255 ViewsLast Modified:
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

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?
Join our community to see this answer!
Unlock 3 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros