Find duplicate records quick and easy with SQL

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


This was first published in May 2001

Dig deeper on RPG iSeries programming

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchEnterpriseLinux

SearchDataCenter

Close