mysql查询当前表最小可用id(id补缺策略)
select min(id+1) from material c where not exists (select id from material where id = c.id+1);
实例:
INSERT INTO material (id, name, content, savename)(
SELECT min(id + 1), '插入数据', '2018-11-02 17:41:34.95',
'93279e3308bdbbeed946fc965017f67a.txt'
FROM material c
WHERE
NOT EXISTS (
SELECT
id
FROM
material
WHERE
id = c.id + 1
)
);
网友评论