Show Menu
Cheatography

Oracle SQL Cheat Sheet (DRAFT) by [deleted]

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Find duplicate rows for specific columns

select column1, column2, count(*) anzahl, 
          listagg(column1,';')
          within group (order by column1) litse
from table
group by column1, column2
order by anzahl desc;

Find duplicate rows for specific columns 2

SELECT  *
FROM    (
        SELECT  t.*, ROW_NUMBER() OVER 
        (PARTITION BY column1, column2 
        ORDER BY column1) AS rn
        FROM    table t
        )
WHERE   rn > 1;
 

listagg

LISTAGG (measure_column [, 'delimiter'])
  WITHIN GROUP (order_by_clause)
The LISTAGG function concat­enates values of the measur­e_c­olumn for each GROUP based on the order_­by_­clause.