I have a query like the following
INSERT INTO connections (`c_id`,`in`,`out`,`ip`,`userID`)
VALUES (
(
SELECT c_id
FROM connections
WHERE (a bunch of conditions)
ORDER BY c_id DESC LIMIT 1
),
'1373799802',
0,
INET_ATON('127.0.0.1'),
4
)
ON DUPLICATE KEY UPDATE `out` = 1
Which throws the following error
1093 - You can't specify target table 'connections' for update in FROM clause
Obviously I can't have a SELECT clause within the insert into on duplicate update
syntax, but I'd really rather do that instead of have 2 queries running. Can anyone tell me how I can do this?