Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
SELECT full_set.row_count AS multiple_rows_count,
COUNT(*)
FROM
(
SELECT col1, <%=__COLUMN_NAMES__%>,
COUNT(1)
OVER
(
PARTITION BY col1, <%=__COLUMN_NAMES__%>
) AS row_count,
ROW_NUMBER()
OVER
(
PARTITION BY col1, <%=__COLUMN_NAMES__%>
ORDER BY 1
) AS row_instance
FROM <%=__TABLE_NAME__%>
) full_set
WHERE
(
-- Restrict the rows returned to only those with duplicates.
(full_set.row_count > 1)
-- Restrict the rows returned to the first instance of duplicated rows.
AND (full_set.row_instance = 1)
)