当前位置:
首页 > 技术 > Mysql 自增id删除后 查询不连续ID

Mysql 自增id删除后 查询不连续ID

mysql自增id,删除后出现id中断修复的sql语句,mysql查询不连续的id

select min(id+a) as id from (
	select id,-1 as a from (select id from t_users order by id asc) t where not exists (select 1 from t_users where id=t.id-1) and id > 1
union
	select id,+1 as a from (select id from t_users order by id asc) t where not exists (select 1 from t_users where id=t.id+1)
) t order by id;

Mysql 自增id删除后 查询不连续ID:等您坐沙发呢!

发表评论

您必须 [ 登录 ] 才能发表留言!