SQL 用于查找多列匹配项(重复项)
SQL for finding multiple column matches (dups)
我正在尝试编写一个查询来查找与其他行具有相同三列的所有行。想象一下,一个人每天只能给另一个人发送一封信,我需要识别“重复”,即使所有的列可能都不相同。
我想查看具有相同 Sender_ID AND Recipient_ID AND [=18 的所有行=]SendDate 与至少另一行相同。
SELECT
Sender_ID, Recipient_ID, SendDate
FROM
Letter_Info
WHERE
??????
这是一场噩梦,还是我只是缺少简单的解决方案?
SELECT Sender_ID, Recipient_ID, SendDate, COUNT(*)
FROM Letter_Info
GROUP BY Sender_ID, Recipient_ID, SendDate
HAVING COUNT(*) > 1
SELECT Sender_ID, Recipient_ID, SendDate
FROM Letter_Info
GROUP BY Sender_ID, Recipient_ID, SendDate
HAVING COUNT(1) > 1
我正在尝试编写一个查询来查找与其他行具有相同三列的所有行。想象一下,一个人每天只能给另一个人发送一封信,我需要识别“重复”,即使所有的列可能都不相同。
我想查看具有相同 Sender_ID AND Recipient_ID AND [=18 的所有行=]SendDate 与至少另一行相同。
SELECT
Sender_ID, Recipient_ID, SendDate
FROM
Letter_Info
WHERE
??????
这是一场噩梦,还是我只是缺少简单的解决方案?
SELECT Sender_ID, Recipient_ID, SendDate, COUNT(*)
FROM Letter_Info
GROUP BY Sender_ID, Recipient_ID, SendDate
HAVING COUNT(*) > 1
SELECT Sender_ID, Recipient_ID, SendDate
FROM Letter_Info
GROUP BY Sender_ID, Recipient_ID, SendDate
HAVING COUNT(1) > 1