Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一张带有房间列表的表格,每个房间都分配了一个房间号。我想删除最高的房间号:
DELETE FROM rooms WHERE roomNb = (SELECT max(roomNb) FROM rooms LIMIT 1)
我希望这可以工作,但是当我尝试在 PHP 中执行这个查询时,我得到了这个 mysqli_error:
string(64) "You can't specify target table 'rooms' for update in FROM clause"
尝试使用加入,
DELETE a FROM rooms a INNER JOIN (SELECT max(roomNb) maxroom FROM rooms) b ON a.roomNb = b.maxroom
我看不出使用子查询/连接的理由......为什么不在ORDER BY子句之后将行移出表的顶部?
ORDER BY
DELETE FROM rooms ORDER BY roomNb DESC LIMIT 1