1

I have a table with id(key).

I was generated a lot of rows. However some rows where not stored because transactions were not completed.

I have total 44000 of rows: first id is 1 & last id is 44045. 

How could I find ids of 44 absent rows?

2
  • 1
    Possible duplicate of MySQL get missing IDs from table Commented Dec 27, 2018 at 0:56
  • @Stony indeed. it works! thank you for your support! Commented Dec 27, 2018 at 0:59

1 Answer 1

3

You can try something like below, to get the rows where no other row with an ID less 1 that the ID of the current row exists and where the ID is not the minimum (which cannot have a predecessor).

SELECT * FROM elbat t1 WHERE NOT EXISTS (SELECT * FROM elbat t2 WHERE t2.id = t1.id - 1) AND t1.id <> (SELECT min(t2.id) FROM elabt t2); 
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer, let me try a solution.
It also works perfect. Advantage of your solution is fast mySQL response, however it returns next ids from a table. I appreciate your support!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.