×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: SQL
Posted by: Jon Nickerson
Added: Sep 19, 2017 8:28 PM
Modified: Mar 30, 2018 7:32 PM
Views: 2
Tags: no tags
  1. WITH dup_recs AS (
  2.     SELECT *
  3.     FROM
  4.       (
  5.         SELECT
  6.           COUNT(*)
  7.           OVER (
  8.             PARTITION BY :dist_val ) dups,
  9.           :dist_val
  10.         FROM :tab
  11.       )
  12.     WHERE dups > 1
  13. )
  14. SELECT DISTINCT * FROM :tab WHERE :dist_val IN (SELECT :dist_val FROM dup_recs);
  15.  
  16. ------------------------------------------------------------------------
  17. ------------------------------------------------------------------------
  18.  
  19. SELECT COUNT(*)
  20. FROM :TABLE
  21. GROUP BY :KEY_COLUMN
  22. HAVING COUNT(*) > 1;