I have a SQL linked list in a single table. I need a query that will return all rows sorted using the previous_item_id to grab the previous row and correctly order the linked list. This SQL query will be used in PHP.
*NOTE: I'm trying to sort a LINKED LIST, not simply ordering by the previous_item_id. So not this:
SELECT * FROM $table_name ORDER BY previous_item_id
I'm a novice at SQL queries, please help :)
Table:
ID EMAIL PREVIOUS_ITEM_ID
1 test@gmail.com NULL
2 test2@gmail.com 1
3 test3@gmail.com 4
4 test4@gmail.com 2
5 test5@gmail.com 3
The sorted rows should return:
test@gmail.com
test2@gmail.com
test4@gmail.com
test3@gmail.com
test5@gmail.com