SQL - Joining multiple records to one record
Posted
by ho
on Stack Overflow
See other posts from Stack Overflow
or by ho
Published on 2010-04-02T07:47:52Z
Indexed on
2010/04/02
7:53 UTC
Read the original article
Hit count: 239
I've got a SQL Server database with the the following tables:
Client (ClientID, ClientName)
SalesAgent (AgentID, AgentName)
Item (ItemID, Description)
Purchase (PurchaseID, ClientID, Price)
PurchaseSalesAgent (PurchaseID, AgentID)
Each purchase is only ever one item to one client but there can have been multiple agents involved. I want to return the following list of columns:
ClientName, Description, Price, Agents
Where Agents is the names of all the agents involved in the purchase. Either as a comma separated list or as multiple columns with one agent in each.
I'm looking for a way that's compatible with SQL Server 2000 but I'd also be interested in if there's a better way of doing it in SQL Server 2008.
© Stack Overflow or respective owner