Quick SQL Reference – Find Duplicate Data In A Table Using Having Clause

Problem Statement: You have a table with duplicate data (say a name) in a column. Find how many times a name occurs in that column.

Simple SQL Solution:

SELECT OBJECT_NAME NAME,
COUNT(OBJECT_NAME) MYCOUNT
FROM GENERALDB.JAVAOBJECTS
GROUP BY OBJECT_NAME
HAVING COUNT(OBJECT_NAME)>0

In above SQL
Table Name = javaobjects
Database Name = generaldb

Here is the original data on a sample table:

Here is the results of running the query on the sample table above.