samedi 7 mars 2015

sqlite linked list in table how to select

Still learning SQL :)


Now I got a table with a autoincrement integer primary key. I have a column called 'next' that link together some entries. I now from other source that there are some list head in this table, and I promess there is no cycle in the list (yet)


So assuming rowid=5 is a head row, I'd like to select any row from the table that follow the 'next' col rowid up to 0 (or NULL).


For now I only see a way by having another column called 'head' and would be 5 for all row into this list, so getting the list would be a simple select head=5, but I am reluctant to multiply the number of columns.


More complicated, I'd like my 'list' to be circular so starting at rowid=5 up to 5 :)


Is that possible to query this?


Thanx for any advises. Cheers, Phi Cheers, Phi


Aucun commentaire:

Enregistrer un commentaire