I am trying to use nested query to avoid having to issue two different queries. My nested query is as shown below;
INSERT INTO roles (
_id,
user_id,
user_role)
VALUES (
((SELECT _id FROM roles ORDER BY _id DESC LIMIT 1)+1), '454', 'USER')
But when I execute I get;
Lookup Error – MySQL Database Error: You can’t specify target table
‘roles’ for update in FROM clause
Is there any work around to this query or I simply can’t do insert and select on the same table?
If you’re using MySQL >= 4.0.14, you can use
INSERT ... SELECT:However, it looks as though you probably just want to make your
_idcolumnAUTO_INCREMENTand then don’t provide any value for it. MySQL will do the rest: