0

I have a table as below. I want to write a query that displays the parent name and other child info for each child.

|    ID     |  Name   |  ParentID  |
|-----------|---------|------------|
|  Parent1  |  aaa    |            |
|  Parent2  |  bbb    |            |
|  Child1   |  ccc    |  Parent1   |
|  Child2   |  ddd    |  Parent1   |
|  Parent3  |  eee    |            |

I want to display the details as below:

|    ID     |  Name   |  ParentID  | ParentName |
|-----------|---------|------------|------------|
| Parent1   |  aaa    |            |            | 
| Parent2   |  bbb    |            |            | 
| Child1    |  xxx    |  Parent1   |  aaa       |
| Child2    |  yyy    |  Parent1   |  aaa       |
| Parent3   |  ccc    |            |            | 
Alejandro Montilla
  • 2,626
  • 3
  • 31
  • 35
gjr
  • 11
  • 2
  • 3
    Possible duplicate of [sql join two table](https://stackoverflow.com/questions/9171963/sql-join-two-table) – Digits Sep 01 '17 at 21:24
  • 1
    Sounds like query with self-joins, that is, joining a table to itself. Review http://allenbrowne.com/ser-06.html and http://www.databasedev.co.uk/self-join_query.html – June7 Sep 01 '17 at 23:50
  • The self join info is great! It resolved my question. Thanks!!! – gjr Sep 06 '17 at 16:23

0 Answers0