0

I have a table with an id and parentID each row have parentID that exist in the same table so the rows are connected and the most primordial row have parentID = 0 how can i get all the rows that are connected to each other in one call of sql?

so i wont have to request in a loop in the client side?

[edit]

it's kinda like a famliy tree

i have

id

name

parentID

so let say Adam is the grandfather Dan is his son and jack is his grandson

1 Adam 0

2 Dan 1

3 Jack 2

and i only have Jack's ID I want to get them all in one query can it be done?

tnx Ali

Sophex
  • 88
  • 6
  • What you are looking for is a `join` or a `nested query` depending on your table design (which from context is hard to tell). Google it, study it, apply it. – Roel Strolenberg May 11 '16 at 17:19
  • @Sophex can more detail like table structure and expected result. – Santosh D. May 11 '16 at 17:20
  • In the future, please search for an answer before posting. When you do post, please include table structures, sample data, expected output, what you've tried, and why/how it didn't work. See http://stackoverflow.com/help/how-to-ask – Tom H May 11 '16 at 17:24
  • tnx guys didnt know how to find what i wanted – Sophex May 11 '16 at 17:28

0 Answers0