When I enter this query in MySQL:
DELETE FROM myTable WHERE ID = ( SELECT Min( ID ) FROM myTable )
The following error message appears:
#1093 - You can't specify target table 'myTable' for update in FROM clause
What is the problem?
What is the correct equivalent?
Basically in MySQL, you cannot update the table that you use in the SELECT part. For details, you can check this behavior, which is documented at: http://dev.mysql.com/doc/refman/5.6/en/update.html
SELECT
In theory, every DELETE is UPDATE , so you get this error.
DELETE
UPDATE
You can simply do the following:
DELETE FROM myTable ORDER BY my_id LIMIT 1;
try
DELETE FROM myTable ORDER BY ID LIMIT 1;
This is because in MySQL you cannot change the same table that you use in the SELECT part.
Read: http://dev.mysql.com/doc/refman/5.6/en/update.html
In MySQL, you cannot change the same table that you use in the SELECT part. This behavior is documented at: http://dev.mysql.com/doc/refman/5.6/en/update.html
Instead of a nested subquery, perform the operation in two parts, or alternatively use the simple where clause.
Try:
$min_id = SELECT Min( ID ) FROM myTable DELETE FROM myTable WHERE ID = $min_id
Now you will not get any errors.
Hurrah!..
DELETE FROM myTable WHERE ID = (SELECT ID FROM myTable ORDER BY ID LIMIT 1)
DELETE FROM myTable ORDER BY ID ASC LIMIT 1
try it
DELETE FROM `table_name` ORDER BY id LIMIT 1;
Source: https://habr.com/ru/post/1402838/More articles:Failed to convert dalvik format with error 1 using adt r17 - androidHow to deploy the same web application twice on WebLogic 11g? - javaHow can I invalidate a single entry from the springmodules cache? - springAndroid: cannot access another SharedPreference application - androidGetting google form in auto-height iframe - javascriptCreating a sequence diagram not from the current code - c #Can I get user country code from Facebook Graph API? - facebookCocoa: stop field editor from autocomplete space key - autocompleteUsing Linkedin to Log In to Your Own iPhone Application - iosTypeError: The result of the expression 'toPage.data ("page")' [undefined] is not an object - in jQuery mobile - javascriptAll Articles