Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Get child table rows in parent column using sql server 2005

Get child table rows in parent column using sql server 2005

Scheduled Pinned Locked Moved Database
databasesql-serversysadmin
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alisolution
    wrote on last edited by
    #1

    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

    J I 2 Replies Last reply
    0
    • A alisolution

      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

      J Offline
      J Offline
      Jorgen Andersson
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • A alisolution

        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

        I Offline
        I Offline
        i j russell
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups