mysql - 如何在 mySQL DB 中查找没有重复的行?
问题描述
我有一张桌子:
--id---name---col1--col2--col3...-colN--created.
--1---myName---col1--col2--col3...-colN--created1.
--2---myName---col1--col2--col3...-colN--created2.
--3---myOtherName---Othercol1--Othercol2--Othercol3...-OthercolN--created3.
id
并且created
字段是唯一的。
其余行有重复 - 完全相同的一组值 (name+col1+col2+col3+..+colN)。
但是,很少有行是完全唯一的。我怎么能找到它们(row 3
在我的例子中)?
解决方案
您可以使用NOT EXISTS
相关子查询从同一个表中选择具有不同 ID 但值相等的行。
SELECT *
FROM elbat t1
WHERE NOT EXISTS (SELECT *
FROM elbat t2
WHERE t2.id <> t1.id
AND t2.col1 = t1.col1
AND t2.col2 = t1.col2
AND t2.col3 = t1.col3
...
AND t2.coln = t1.coln);
推荐阅读
- xml - Cvc-complex-type.2.4.a:发现无效内容以元素“”开头
- apache-spark - 在 Spark 中调整 DAG/沿袭图
- java - 谁能解释为什么 C 和 Java 的输出不同?
- python - 如何从上传的 csv 文件中读取数据并使用 django 进行查看?
- angular - Angular - 在另一个方法之前执行一个方法
- javascript - 如何点击需要与木偶师?
- r - gganimate 中两个不同的 geom_smooth() 对象之间的转换
- c++ - DBus 拒绝向系统总线上的自定义服务发送消息
- codenameone - 根据国家/地区格式化电话号码
- excel - 将多行文本单元格从 Word 表复制到 Excel 单元格