Method A. You can get a released version of your data using
SELECT field1, field2, ... INTO Deduped FROM Source GROUP BY field1, field2, ...
For example, for your sample data,
SELECT name, number FROM Source GROUP BY name, number
gives
alex 1 hary 34 liza 32
then just delete the old table and rename the new one. Of course, there are a number of fantastic solutions in place, but this is the clearest way to do this.
Method B. The in-place method is to create a primary key and remove duplicates in this way. For example, you can
ALTER TABLE Source ADD sid INT IDENTITY(1,1);
what makes Source look like this
alex 1 1 alex 1 2 liza 32 3 hary 34 4
then you can use
DELETE FROM Source WHERE sid NOT IN (SELECT MIN(sid) FROM Source GROUP BY name, number)
which will give the desired result. Of course, "NOT IN" is not entirely effective, but it will do the job. Alternatively, you can HELP a JOINT of a grouped table (possibly stored in a TEMP table) and do this DELETE this way.
source share