2015-04-29 47 views
1

我在這個查詢的問題:此INSERT MAX + 1查詢有什麼問題?

INSERT INTO invoices(invuid, linenumber) VALUES (?, SELECT(SELECT max(linenumber)+1 FROM invoices WHERE invuid=?))

口口聲聲說:"General error: 1093 You can't specify target table 'invoices' for update"

回答

1

你的語法是無效的,可以使用INSERT INTO ... SELECT和刪除values部分是這樣的:

INSERT INTO invoices(invuid, linenumber) 
SELECT ?, max(linenumber)+1 FROM invoices WHERE invuid=?