Find duplicate query

Post Reply
barry.marcus
Posts: 288
Joined: Thu Nov 16, 2006 1:05 pm

Find duplicate query

Post by barry.marcus »

If I have a simple table with the following structure

id counter
WKU varchar

What query will show me the WKUs that are duplicated? For example, assume I have the following WKU data:

WKU
---
AAAA
BBBB
BBBB
BBBB
CCCC
DDDD
DDDD
EEEE

What query will display the following result, since 'BBBB' and 'DDDD' are duplicated in the table:

WKU
---
BBBB
DDDD

Thanks in advance for your help.
User avatar
John
Site Admin
Posts: 2622
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

Find duplicate query

Post by John »

You can do the following:

select WKU, count(*) N from T group by WKU having N > 1;

which will also display the count for the duplicated fields, e.g.

WKU N
-------------
BBBB 3
DDDD 2
John Turnbull
Thunderstone Software
barry.marcus
Posts: 288
Joined: Thu Nov 16, 2006 1:05 pm

Find duplicate query

Post by barry.marcus »

Thank you. That's what I need.
Post Reply