开发者

Is this mysql query possible?

INSERT INTO example_table(`id`,`name`) VALUES (MAX(id)+1,`superman`) ;

The above query doesn't work, wh开发者_如何学编程at could be the correct equivalent of this query ? I want the id column to behave like autoincrement column, but I cannot have it as autoincrement for some reasons.


INSERT
INTO    example_table (id, name)
SELECT  MAX(id) + 1, 'superman'
FROM    example_table


Normal you have to check the A_I check box, this is in the latest version of MySQL, if you have created the table, and after you want to activate auto increment it wouldn't be possible.

You can try

INSERT INTO second_table (fk, a, b, c) VALUES (LAST_INSERT_ID(), 1, 2, 3)

Success

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜