You can't specify target table 'downloads' for update ?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mayanktalwar1988
Forum Contributor
Posts: 133
Joined: Wed Jul 08, 2009 2:44 am

You can't specify target table 'downloads' for update ?

Post by mayanktalwar1988 »

in phpmyadmin when i ran this query

Code: Select all

delete from downloads where id not in (select max(id) from downloads  group by downloadlink)
it throws this error

Code: Select all

#1093 - You can't specify target table 'downloads' for update in FROM clause
actualyy i m deleting duplicate rows based on one column for which i m checking duplicate..i group the results by duplicate column ..then id is the autoincrement key..after that i delete all rows in group except the one that has max id..so logic is correct i think but its not running..
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: You can't specify target table 'downloads' for update ?

Post by Darhazer »

You cannot update a table / delete from table and use the same table in a subquery.
You can however lock the table, select the IDs and then perform deletion.
Post Reply