Sum up counts in subquery I am writing a query to check if I have got duplicates in a certain column.

SELECT COUNT(thecol) FROM thetable WHERE thecol IS NOT NULL GROUP BY thecol 
  HAVING COUNT(*) &gt; 1


That will give me an output like

3
5
6


Which of course is the number of records for each value of thecol where thecol is not unique.

Now how do I only get the sum 14? Should I have the existing query as a subquery?
Does this do what you want?

SELECT SUM(x.records)
FROM 
(
    SELECT COUNT(thecol) AS records
    FROM thetable 
    WHERE thecol IS NOT NULL 
    GROUP BY thecol 
    HAVING COUNT(*) &gt; 1
) AS x