BlogPhotosContact

Topics

Finding gaps in sequence

Here is a subselect query I have used successfully to get a list of missing serial numbers in a auto-incremented (or not so automatic in my case) sequence :

SELECT A.number + 1
FROM orders AS A
WHERE NOT EXISTS (
SELECT B.number FROM orders AS B
WHERE A.number + 1 = B.number)
GROUP BY A.number;

Yes, simple but effective :)

Will work only in MySQL 4.1+ though because it's a subselect.

Comments (0)  Permalink

Comments

Add a comment

The Trackback URL to this comment is:
http://golgote.freeflux.net/blog/plugin=trackback(26).xml

No new comments allowed (anymore) on this post.