TABLEA:
id
scu
DELETE FROM TABLEA
WHERE id NOT IN (
(
SELECT MAX(id)
FROM TABLEA
GROUP BY scu
)
)
Any ideas why it's throwing that error?
| SitePoint Sponsor |





TABLEA:
id
scu
DELETE FROM TABLEA
WHERE id NOT IN (
(
SELECT MAX(id)
FROM TABLEA
GROUP BY scu
)
)
Any ideas why it's throwing that error?


Create a temporary table from the SELECT query and use that as the condition for your DELETE, then drop the temporary table.Originally Posted by http://dev.mysql.com/doc/refman/5.0/en/delete.html
17-29% of paid ad clicks are fraudulent. Get protected with Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more.





thanks.





According to a bug report (#5037) there is a workaround that's something like this:
Unfortunately I'm not sure how that would compare performance wise against what Dan recommended, and it is somewhat version specific (unless that person only tested it on 5).This works in MYSQL version 5.0.20a-standard
DELETE FROM TABLE1 WHERE TABLEID IN
(
select TABLEID from (SELECT TABLEID FROM TABLE1 WHERE TABLEID = 2689891) AS
NEWTABLENAME
);





chris - most helpful - thanks very much
Bookmarks