php - Mysql, finding missing numbers in a sequence -
this question has answer here:
- sql: find missing ids in table 15 answers
i have huge table couple hundred thousand records. have unique id first column though missing in sequence of numbers.
i trying show list of numbers missing individually.
so example:
10029 10032 10034 10036
i trying show:
10030 10031 10033 10035
i found query seems missing numbers when there's range:
select t1.id+1 missing data t1 left join data t2 on t1.id+1 = t2.id t2.id null
result:
10030 10033
as can see, 10031 , 10035 missing list.
perhaps starting point. not tested, might work
select @min := (select min(id) yourtable); // smallest id in table select @last := @min; // cache min value clause select id, id - @last difference, @last := id yourtable id > @min order id asc having difference > 1
it won't give individual missing ids, it'll tell gaps are, , how big are.
Comments
Post a Comment