Get child table rows in parent column using sql server 2005
-
hi everybody, In sql server 2005 I have a parent Table Person(PersonID,PersonName) PersonID personName 1 abc 2 xyz. and child Table BankAccount(AccountId,PersonId,Bank) AccountId PersonId Bank 1 1 a 2 1 b 3 1 c 4 2 d 5 2 e I Want to display result this way. personId PersonName Bank 1 abc a,b,c 2 xyz d,e Means display child tables rows result in parent table column.
modified on Wednesday, June 30, 2010 4:19 PM
-
hi everybody, In sql server 2005 I have a parent Table Person(PersonID,PersonName) PersonID personName 1 abc 2 xyz. and child Table BankAccount(AccountId,PersonId,Bank) AccountId PersonId Bank 1 1 a 2 1 b 3 1 c 4 2 d 5 2 e I Want to display result this way. personId PersonName Bank 1 abc a,b,c 2 xyz d,e Means display child tables rows result in parent table column.
modified on Wednesday, June 30, 2010 4:19 PM
You fail to mention what database you're using. In Oracle you can use:
SELECT personid
,personname
,LISTAGG(bank, ',') WITHIN GROUP (ORDER BY bank) AS bank
FROM parent p,child c
WHERE p.personid = c.personid
GROUP BY personid,personname;"When did ignorance become a point of view" - Dilbert
-
hi everybody, In sql server 2005 I have a parent Table Person(PersonID,PersonName) PersonID personName 1 abc 2 xyz. and child Table BankAccount(AccountId,PersonId,Bank) AccountId PersonId Bank 1 1 a 2 1 b 3 1 c 4 2 d 5 2 e I Want to display result this way. personId PersonName Bank 1 abc a,b,c 2 xyz d,e Means display child tables rows result in parent table column.
modified on Wednesday, June 30, 2010 4:19 PM
If you want to search for the answer, look at my last reply to the question below. If you want the answer look at my second reply to indian143 (20:38 28 Jun '10) four questions down.