Problem Fetching Duplicate Records with SQL/400 -- Follow-up

Article ID: 16963

We received e-mails regarding Paul Conte's tip in the last issue from Antoon van Os and Karen Hodge, who offer an alternative SQL statement to fetch duplicate records:

SELECT key1, key2..., keyn 
FROM file 
GROUP BY key1, key2..., keyn
HAVING count(*) > 1

Here's a response from Paul Conte:

Thanks for the suggestion. Your tip is a straightforward way to get a list (without duplicates) of all keys that are duplicated in two or more rows.

My answer was based on the reader's original Oracle query. For whatever reason, the reader was trying to get the set of "duplicates" that did _not_ include the row with the highest RowId. The problem of getting a list of duplicated keys obviously doesn't require RowId (or an SQL/400 alternative), so I assumed the reader wanted a solution to the precise problem they posed.

ProVIP Sponsors

ProVIP Sponsors