0

I created a table with name "vegs" and inserted values just like this.

    id  name            parent
--------------------------------------
    1   fruits          0
    2   Apple           1
    3   Orange          1
    4   Grape           1
    5   Green Apple     2
    6   Red Apple       2

I want to recursively fetch all parents of the child "6".

Colin 't Hart
  • 9,455
  • 15
  • 36
  • 44
user38957
  • 29
  • 1
  • 1
  • 2

1 Answers1

5

Recursive queries cannot be done with pure SQL when it comes to MySQL.

I have written posts on how to use Stored Procedures to accomplish this

Give them a Try !!!

NOTE : This post, originally May 24, 2014, predates MySQL 8.0, which now has CTEs.

RolandoMySQLDBA
  • 185,223
  • 33
  • 326
  • 536