Jump to content

How can i find missing numbers?


Exoon

Recommended Posts

Run one of these queries mate, assuming your id column is named 'id', also change table_name to the name of your table:

 

SELECT a.id + 1 AS 'missing' FROM users_test AS a WHERE NOT EXISTS (SELECT b.id FROM table_name AS b WHERE a.id + 1 = b.id) AND id < (SELECT MAX(id) FROM table_name)

 

or

 

SELECT l.id +1 AS 
START , MIN( fr.id ) -1 AS 
STOP 
FROM table_name AS l
LEFT OUTER JOIN table_name AS r ON l.id = r.id -1
LEFT OUTER JOIN table_name AS fr ON l.id < fr.id
WHERE r.id IS NULL 
AND fr.id IS NOT NULL 
GROUP BY l.id, r.id
LIMIT 0 , 30

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.