Have you ever needed to identify records in a file that are duplicate records and struggled to find an elegant, simple and quick solution without having to write a program every time?
Use the GROUP and COUNT(*) features of SQL together to identify the duplicate records in no time...
Include the key fields in both the SELECT and the GROUP fields (in the same order). The key fields are whatever fields are required to make the definition of 'duplicate' unique to your situation.
Don't forget that you can redirect the output of your SQL operations to a file or a report using the F13=Services and option 1 to Change session attributes.
SELECT CONO, ITEM, Count(*)
FROM mylib/myfile
GROUP BY CONO, ITEM
HAVING count(*) > 1
Requires Free Membership to View
Register today to access targeted resources from our editorial writers and independent industry experts including news, tips, and advice to help you do your job more efficiently and effectively. Stay informed on the hottest topics and biggest challenges faced by IT professionals working with iSeries products and services.
This was first published in May 2001