Xtremesupremacy3 Xtremesupremacy3 -4 years ago 45
MySQL Question

MySQL: Display duplicates matching two columns

I have a table containing many columns.
What I'm trying to do is find a way I can display duplicates.

My table is info, and whilst it contains many columns, the ones I'm interested in is 'id' and 'shipping_date'. Whilst both shipping_date and id on their own may appear many times, they must not appear more than once together.
For instance

id shipping_date
-- -------------
C123 2013-01-31
C123 2012-12-19


is perfectly fine, but if 'c123' and '2013-01-31' together were to appear more than once, I would like it display like above.

I'm at a loss and I'm quite a newbie.
Any help is appreciated.

Answer Source

Use:

select id, shipping_date from T group by id, shipping_date having count(*) > 1;

EDIT: this allows you to find which records are duplicated, not to show duplicated records only once (if that's what you meant).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download