3

I have following SQL table

Area

id     name         parent_id
1      Pune         null
2      Mumbai       null
3      area1        1
4      area2        3

Here I have logical foreign key parent_id so that area2 has the parent area1 and area1 has parent Pune. Here I want to select topmost parent of any subarea. For ex. when i search area2 then it will give result Pune.

Tushar Kulkarni
  • 323
  • 4
  • 19

1 Answers1

0

mysql does not support hierarchical joins (e.g. WITH RECURSIVE)

You can either try this solution:

Hierarchical queries in MySQL

Or manipulate the recursion within php or any other server-side language you are using

Since you asked in the comments regarding Oracle / MSSQL: Oracle,MSSQL

Community
  • 1
  • 1
Uri Goren
  • 13,386
  • 6
  • 58
  • 110