我有一张 table :
--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)。
但是,很少有行是完全唯一的。 如何找到它们(在我的示例中为第 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);
关于mysql - 如何查找 mySQL DB 中没有重复的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54346150/