You can rewrite this query without using a MySQL variable..
INSERT INTO
GSM_Parent (OrderNumber)
values ( (SELECT COALESCE( MAX( OrderNumber ) , 0 ) +1 FROM GSM_Parent) )
Thanks, but I got the following error:#1093 - You can't specify target
table 'GSM_Parent' for update in FROM clause .
Indeed i missed you used the same table twice, the query below should work.
INSERT INTO
GSM_Parent (OrderNumber)
VALUES (
(SELECT OrderNumber FROM (
SELECT
(COALESCE(MAX(OrderNumber), 0) + 1) AS OrderNumber
FROM
GSM_Parent
) AS GSM_Parent
)
)
@Jarth 's query from the comments is also possible then you need to write
INSERT INTO
GSM_Parent (OrderNumber)
SELECT
OrderNumber
FROM(
SELECT COALESCE(MAX(OrderNumber), 0) +1 AS OrderNumber FROM GSM_Parent
) AS GSM_Parent
No comments:
Post a Comment