当我在MySQL中输入以下查询:
DELETE FROM myTable WHERE ID = ( SELECT Min( ID ) FROM myTable )
我收到了以下错误信息:
#1093 - You can't specify target table 'myTable' for update in FROM clause
问题是什么?
正确的等价物是什么?
当我在MySQL中输入以下查询:
DELETE FROM myTable WHERE ID = ( SELECT Min( ID ) FROM myTable )
#1093 - You can't specify target table 'myTable' for update in FROM clause
问题是什么?
正确的等价物是什么?
基本上在MySQL中,您不能对用于SELECT
部分的表进行更新。有关详细信息,请查看文档:http://dev.mysql.com/doc/refman/5.6/en/update.html
理论上每个DELETE
都是一个UPDATE
,这就是为什么会出现此错误的原因。
您可以简单地执行以下操作:
DELETE FROM myTable
ORDER BY my_id
LIMIT 1;
try
DELETE FROM myTable ORDER BY ID LIMIT 1;
这是因为在MySQL中,您不能修改用于SELECT部分的同一张表。
$min_id = SELECT Min( ID ) FROM myTable
DELETE FROM myTable WHERE ID = $min_id
Cheers..!
DELETE FROM myTable WHERE ID = (SELECT ID FROM myTable ORDER BY ID LIMIT 1)
DELETE FROM myTable ORDER BY ID ASC LIMIT 1
试试这个
DELETE FROM `table_name` ORDER BY id LIMIT 1;