简体   繁体   English

删除mysql中的重复项(两个参数)

[英]Delete duplicates in mysql (two parameters)

I'm trying to delete duplicates from a table which contains cities, there may however be multiple cities with the same name across different countries, example from table: 我正在尝试从包含城市的表中删除重复项,但是在不同国家/地区可能存在多个具有相同名称的城市,例如表中的示例:

+------+----------+---------------------+ | locId | country | city | +------+----------+---------------------+ | 1 | DE | Hamburg | | 2 | US | Hamburg | | 3 | DE | Hamburg | | 4 | DE | Hamburg | | 5 | US | Hamburg | +------+----------+---------------------+

Now 1,3,4 are the same (different zip codes, but that doesn't matter, safe to remove) and 2,5 are the same. 现在1,3,4相同(不同的邮政编码,但是没关系,可以安全删除)和2,5相同。 What query could be run to leave only 1 and 2 in the table and deleting the other duplicates ? 可以运行什么查询以仅在表中保留1和2并删除其他重复项?

DELETE id FROM table t1, table t2 WHERE t1.country <> t2.country AND t1.city = t2.city

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM