0

I have written the below query. I do not think it is the optimum way. The scenario is - given a child, I want to fetch all rows corresponding to its parent(root).

select * from TableA where column_root = 
(select column_root from TableA where column_child = 123)
KeenUser
  • 5,305
  • 14
  • 41
  • 62

1 Answers1

0

You can use JOIN:

select T1.* from 
    TableA T1 join
    TableA T2 ON T1.column_root=T2.column_root
where T2.column_child = 123

Sample result in SQL Fiddle

Raging Bull
  • 18,593
  • 13
  • 50
  • 55