Xtremesupremacy3
Xtremesupremacy3

Reputation: 65

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.

Upvotes: 1

Views: 47

Answers (5)

Wachaga Mwaura
Wachaga Mwaura

Reputation: 3610

select id, shipping_date from table ORDER BY id,shipping_date

The above will show all the duplicates, no grouping them out using distinct filter.

Upvotes: 0

Sathish
Sathish

Reputation: 4487

select id, shipping_date from Table group by id,shipping_date

Upvotes: 0

rand
rand

Reputation: 698

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).

Upvotes: 1

valex
valex

Reputation: 24144

You can use DISTINCT keyword:

select distinct id, shipping_date from Table

Upvotes: 1

naveen goyal
naveen goyal

Reputation: 4629

As I understand your question this is my Possible answer of your question.

select id, shipping_date from tablename group by id, shipping_date

Upvotes: 1

Related Questions