Now, I'm trying to get the highest value from a column in a table then increment it(+1), then update another records same column to that number. I'm scripting in PHP, variable $SQL is sent to MySQL.
$SQL="
UPDATE `router`
SET `Line Order`= (SELECT 1 + IFNULL(MAX(`Line Order`), 0) FROM `router`)
WHERE `RN`=?
";
$stmt = $GLOBALS['mySQLConnection']->prepare($SQL);
echo $GLOBALS['mySQLConnection']->error;
The error is: You can't specify target table 'router' for update in FROM clause How are we suppose to do this, without writing separate queries in php