MySQL Forums
Forum List  »  Newbie

Re: How to create a solid sequence?
Posted by: Gary Golden
Date: June 24, 2011 11:59PM

Problems comes when we delete records from the beginning of sequence.
If there is ids:
2
3
4
100

It will not search "backwards" and will return 5 instead of 1

It tried experiments with this query, but with no luck.


SELECT * FROM test AS a
LEFT JOIN test AS b ON a.id + 1 = b.id
LEFT JOIN test AS c ON a.id -1 = c.id
WHERE b.id IS NULL OR c.id IS NULL;

This is going to be a headache :)

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.