0

When a row is duplicated in our system, it inserts the new row with a reference back to the ID of the one it was duplicated from.

If that new row is then duplicated, it has a reference back to the row it was duplicated from and so on.

What I cant work out is how to follow this trail in a SELECT.

Take the following data...

+------+-------------------+
|  ID  |  duplicated_from  |
+------+-------------------+
|  1   |  NULL             |
|  2   |  1                |
|  3   |  2                |
|  4   |  NULL             |
+------+-------------------+

So, given ID 1, how would you look up all the slides in the chain that have been duplicated off it?

Or is this something that will have to be done at an application level?

Legionar
  • 7,472
  • 2
  • 41
  • 70
Matt Bryson
  • 2,286
  • 2
  • 22
  • 42

1 Answers1

0

Seems that you are after a recursive query, i found this solutions that may help you How to create a MySQL hierarchical recursive query

HTH

Community
  • 1
  • 1
andres
  • 143
  • 4