如何删除MySql中的重复项?

时间:2022-06-28 23:41:02

I have a guest list of names like "mark Anthony", "James Bond" etc.. about 1000 of them. Now in another table i have similar list. I want to clean my list of name so that remove any name that is also in list 2.

我有一个名单的客人名单,如“马克安东尼”,“詹姆斯邦德”等......大约1000个。现在在另一个表中我有类似的列表。我想清理我的名称列表,以便删除列表2中的任何名称。

So that if James bond is on list 2 then it should remove that field from list 1.

因此,如果詹姆斯债券在列表2上,那么它应该从列表1中删除该字段。

3 个解决方案

#1


1  

Try this;)

DELETE list1 FROM list1
LEFT JOIN list2 ON list1.name = list2.name
WHERE list2.name IS NOT NULL;

#2


0  

Here you go.

干得好。

Delete FROM table1
WHERE name1
IN 
(
SELECT
name2
FROM table2
);

#3


0  

You can do it using a subselect.

您可以使用子选择来完成。

delete
from list1
where exists (select 1
              from list2
              where list2.name = list1)

#1


1  

Try this;)

DELETE list1 FROM list1
LEFT JOIN list2 ON list1.name = list2.name
WHERE list2.name IS NOT NULL;

#2


0  

Here you go.

干得好。

Delete FROM table1
WHERE name1
IN 
(
SELECT
name2
FROM table2
);

#3


0  

You can do it using a subselect.

您可以使用子选择来完成。

delete
from list1
where exists (select 1
              from list2
              where list2.name = list1)