Jump to content

How can i find missing numbers?


Exoon

Recommended Posts

Hi,

 

I just have a database with numbers 1-5000 but when i was adding them i missed a few out and cant figure out which ones for example 4255 might be missing.

 

I can export the database but it will just be numbers from 1 ending in 5000.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.