Home > other >  SQL for finding multiple column matches (dups)
SQL for finding multiple column matches (dups)

Time:02-17

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?

CodePudding user response:

SELECT *
FROM Letter_Info
GROUP BY Sender_ID, Recipient_ID, SendDate
HAVING COUNT(*) > 1

CodePudding user response:

SELECT Sender_ID, Recipient_ID, SendDate
FROM Letter_Info
GROUP BY Sender_ID, Recipient_ID, SendDate
HAVING COUNT(1) > 1
  • Related