删除SQL查询中的重复记录语法错误

时间:2014-04-08 07:44:30

标签: mysql sql

我尝试从表中删除重复记录

我的SQL查询是:

 DELETE FROM products_description AS t1 WHERE EXISTS (
SELECT 'products_id', 'site_language_id'
FROM products_description AS t2
WHERE t2.products_id = t1.products_id
AND t2.site_language_id = t1.site_language_id
);

它给出了这个错误:

#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 'as t1
where  exists (select 'products_id','site_language_id' from products_desc' at line 1

我不知道遗失了什么?

2 个答案:

答案 0 :(得分:0)

MySQL因为存在语法错误而抱怨。尝试用反引号(`)替换引号(')。

虽然小心!然后查询将起作用,但会删除所有行而不只是重复....

答案 1 :(得分:0)

删除所有有重复的记录

DELETE FROM products_description
WHERE product_id IN (
                     SELECT product_id FROM( Select product_id,site_language_id
                                             From products_description 
                                             Group By product_id,site_language_id
                                             Having Count(*)>1
                                           ) As X
                    )As Y