Generate SQL to identify duplicates