Possible Duplicate:
Is it possible to make a recursive SQL query?
Imagine an application where one would want to keep a history of the changes made to a 'record' in a database.
This can be realized by introducing a column 'revised_id' which points to the newer version of the record.
id value revised_id
--------------------------------------------------
1 Initial value... 3
2 Value of a different record Null
3 Value which has been altered 4
4 Value which has been altered again Null
The table illustrates two 'actual records', one of which has been altered two times
Getting all the latest versions simply means adding revised_id = null to the WHERE clause. To get the previous version simply: SELECT * FROM table WHERE revised_id = $current_id
My questing is: would it be possible to select all te previous versions of a given record?(The problem being that simple comparisons do not suffice because the records to be selected are 'chained' together.)