PrepZone Logo
PrepZone
Back to Database

Database · Medium

Delete duplicate rows keeping only the one with the lowest id.

DatabaseSQL QueriesSeniorDML

Answer preview

Keep the surviving row per business key with MIN(id) (or ROW_NUMBER()) and delete everything else — demonstrated on a throwaway demo_contacts table so the reference data stays intact.…