Skip to content
Advertisement

SQL for finding multiple column matches (dups)

I’m trying to write a query to find all rows that have three columns in common with other rows. Imagine a person can only send one letter to another per day and I need to identify “dups” even though all of the columns may not be the same.

I want to see all rows that have the same Sender_ID AND Recipient_ID AND SendDate in common with at least one other row.

SELECT
Sender_ID, Recipient_ID, SendDate
FROM
Letter_Info
WHERE
??????

Is this a nightmare to write or am I just missing the simple solution?

Advertisement

Answer

SELECT Sender_ID, Recipient_ID, SendDate
FROM Letter_Info
GROUP BY Sender_ID, Recipient_ID, SendDate
HAVING COUNT(1) > 1
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement