Assuming there can't be any duplicate order
values for a user_id
, this should work:
SELECT user_id, max(`order`)-min(`order`)+1 order_range_size, count(*) c
GROUP BY user_id
HAVING c != order_range_size
This doesn't tell you which order
is missing from the range; I hope that's OK.