Duplicates

Checking for duplicates

    Any of these will identify values appearing more than once:

    1. GROUP BY and HAVING
      select col1,count(*)
        from table_name a
       where ...
       group by col1
      having count(*) > 1;
      
    2. Correlated subquery
      select col1
        from table_name a
       where ...
         and 1 < (select count(*)
                    from table_name b
                   where b.col1 = a.col1);
      
    3. CSQ to predicate EXISTS
      select col1
        from table_name a
       where ...
         and exists
             (select 'x'
                from table_name b
               where b.col1 = a.col1
                 and b.rowid != a.rowid);
      


Top Next