If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > displaying non-duplicate keys of all duplicate entries

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-30-04, 17:55
Disson Disson is offline
Registered User
 
Join Date: Mar 2004
Posts: 15
displaying non-duplicate keys of all duplicate entries

Ok, so I'm checking for duplicate data in a table. Let's say it has 3 data fields and a key field (i.e. "ID", "FIRST", "MIDDLE", "LAST"). No keys are duplicated. If I find entries that have the same data in each of the non-key fields, I want to know the keys for all those entries. I have been able to find duplicate rows using this...

Code:
SELECT
    TABLE."FIRST", TABLE."MIDDLE", TABLE."LAST"
FROM
    TABLE
GROUP BY
    TABLE."FIRST", TABLE."MIDDLE", TABLE."LAST"
HAVING
    COUNT(*) > 1
Unfortunately I've found no way to incorporate the return of the TABLE."ID" for every duplicated entry. Is there some way I can join the result with the db.table to find this, or some other way to make this happen?

Thanks,
Dean
Reply With Quote
  #2 (permalink)  
Old 03-30-04, 18:06
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Sure, use:
PHP Code:
SELECT
    A
."ID"A."FIRST"A."MIDDLE"A."LAST"
FROM TABLE AS A
WHERE 1 
< (SELECT Count(*)
   
FROM TABLE AS B
   WHERE  B
."FIRST" A."FIRST"
      
AND   B."LAST" A."LAST"
      
AND   B."MIDDLE" A."MIDDLE"
-PatP
Reply With Quote
  #3 (permalink)  
Old 03-30-04, 18:50
Disson Disson is offline
Registered User
 
Join Date: Mar 2004
Posts: 15
Thanks, that worked well, although it takes a good while for the server to process the query.
Reply With Quote
  #4 (permalink)  
Old 03-30-04, 18:52
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Indicies would help this query a lot, particularly an index on last, first, middle.

-PatP
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On