开发者

Make a column the max of another +1 PL/SQL?

开发者 https://www.devze.com 2023-02-09 14:22 出处:网络
I cant use auto increment in phpmyadmin for this but I would like to see if its possible and find a way to get the max(displayorder) +1 every time there\'s a row insert. Could someone sh开发者_JAVA技巧

I cant use auto increment in phpmyadmin for this but I would like to see if its possible and find a way to get the max(displayorder) +1 every time there's a row insert. Could someone sh开发者_JAVA技巧ow me how this is done if it's possible? I am using mysql.


Why can't use auto_increment?

This should work.

INSERT INTO yourTable (displayOrder, someColumn, someColumn)
SELECT sq.displayOrder, someValueToBeInserted, someValueToBeInserted
FROM (
  SELECT MAX(displayOrder) + 1 AS displaOrder
  FROM yourTable
) AS sq

but be aware that it is unreliable.

0

精彩评论

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