So i have a table with duplicate entries. I want to keep only ONE of each entry with a common ECSOID value, but the ONE row i want to keep is the ONE with the most data in all of it's columns. Typically, i use something like this JUST to get rid of duplicates, but it contains no where clause keeping the row that i want:this query is from an unrelated table:Delete d FROM(SELECT personid, firstname, lastname, middlename, ROW_NUMBER()OVER(ORDER BY personid) AS RowNum FROM persondata)DJOIN(SELECT personid, firstname, lastname, middlename, ROW_NUMBER()OVER(ORDER BY personid) AS RowNum FROM persondata)Eon D.personid = E.personidAND D.RowNum < E.RowNumdelete FROM persondata where Firstname='' AND lastname='' AND dob IS NULL
here's a snapshot from the table i want to deal with. it has many other columns than those you see here:ECSOID DOB Race SexID Hair eyesDCSO00MNI144747 1939-11-15 00:00:00.000 W 15 NULL DCSO00MNI144747 1939-11-15 00:00:00.000 W 15 BLN BRODCSO00MNI144747 1939-11-15 00:00:00.000 W 15 BLN BRODCSO00MNI144747 1939-11-15 00:00:00.000 W 15 GRY BRODCSO00MNI144747 1939-11-15 00:00:00.000 W 15 BLN BRODCSO00MNI144747 1939-11-15 00:00:00.000 W 15 BLN BRODCSO00MNI147038 1972-10-29 00:00:00.000 W 14 BRO BRODCSO00MNI147038 1972-10-29 00:00:00.000 W 14 BRO BRODCSO00MNI147038 1972-10-29 00:00:00.000 W 14 BRO BRODCSO00MNI147038 1972-10-29 00:00:00.000 W 14 BRO BRODCSO00MNI147038 1972-10-29 00:00:00.000 W 14 BRO BRODCSO00MNI147038 1972-10-29 00:00:00.000 W 14 BRO BRODCSO00MNI147038 1972-10-29 00:00:00.000 W 14 BRO BRODCSO00MNI147038 1972-10-29 00:00:00.000 W 14 BRO BRODCSO00MNI147279 1940-07-07 00:00:00.000 B 14 BLK BRODCSO00MNI147279 1940-07-07 00:00:00.000 B 14 BLK BRODCSO00MNI147279 1940-07-07 00:00:00.000 B 14 BLK BRODCSO00MNI147279 1940-07-07 00:00:00.000 B 14 BLK BRODCSO00MNI147279 1940-07-07 00:00:00.000 B 14 BLK BRODCSO00MNI147279 1941-07-07 00:00:00.000 B 14 BLK BRODCSO00MNI147279 1940-07-07 00:00:00.000 B 14 BLK BRODCSO00MNI147279 1940-07-07 00:00:00.000 B 14 BLK BRODCSO00MNI151477 1956-12-21 00:00:00.000 W 14 BRO GRNDCSO00MNI151477 1956-12-21 00:00:00.000 W 14 BRO DCSO00MNI151477 1956-12-21 00:00:00.000 W 14 BRO GRN
Is there a modification i can apply to the query above which will leave intact what i want?