1

My query is:-

delete from api_data 
WHERE local_id NOT IN( SELECT MAX(local_id) 
                       FROM api_data 
                       GROUP BY local_id);

But i am getting error which says:

You can't specify target table 'api_data' for update in FROM clause.

Any Help?

DavidG
  • 104,599
  • 10
  • 205
  • 202

1 Answers1

3

In MySQL you can't delete from the same table you are selecting from. But you can use another subquery to cover that

delete from api_data
WHERE local_id NOT IN
(
  select * from 
  (
    SELECT MAX(local_id) FROM api_data GROUP BY local_id
  ) tmp
);
juergen d
  • 195,137
  • 36
  • 275
  • 343