Farhad Farhad - 5 months ago 18
MySQL Question

MySql - How remove duplicate records

When running this query:

DELETE FROM news e
GROUP BY e.itemId, e.tag_id
HAVING COUNT(e.itemId) > 1
AND COUNT(e.tag_id) > 1


I get this error:


[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'e

Answer

for remove duplicate records, use this query

DELETE
    n1
FROM
    news n1,
    news n2
WHERE
    n1.id < n2.id
AND n1.itemId = n2.itemId
AND n1.tag_id = n2.tag_id
AND n1.tag_id IS NOT NULL