开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜