"id" "parent" "name"
"1" "0" "Books"
"2" "1" "Crime Fiction"
"3" "2" "Death On the Nile"
From something like the above, how can I select the name
of the parent row along with the name of the child
. Here, the name of the child row will be supplied. I need to get the name
of the parent.
Desired output:
@id = 3
Crime Fiction //This is the name of the parent row - in this case 2
Death on the Nile // This is the name of the row who's id was supplied.
How is selecting inside the same table done?
select parent.name, child.name
from your_table child
left join your_table parent on child.parent = parent.id
where child.id = 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With