Find missing ids in MySql

select t1.id – 1 as missing_id from messages t1 left join messages t2 on t2.id = t1.id – 1 where t2.id is null order by missing_id desc

Leave a comment

Your email address will not be published. Required fields are marked *