Skip to content
Advertisement

Delete duplicate records from a SQL table without a primary key

I have the below table with the below records in it

I dont have any primary key in this table .But i have the above records in my table already. I want to remove the duplicate records which has the same value in EmpId and EmpSSN fields.

Ex : Emp id 5

How can I frame a query to delete those duplicate records?

Advertisement

Answer

Add a Primary Key (code below)

Run the correct delete (code below)

Consider WHY you woudln’t want to keep that primary key.


Assuming MSSQL or compatible:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement