Remove Duplicate Row Using Query In SQL Server

Sesuai dengn judul "Remove Duplicate Row Using Query In SQL Server". Pada posting kali ini kita akan belajar cara menggunakan conditional delete untuk menghapus salah 1 baris dari 2 buah baris duplikat dengan menghapus baris yang memiliki nilai paling kecil.


Remove Duplicate Row Using Query In SQL Server


Script untuk menghapus seperti terlihat dibawah ini :

delete sap_volume_dsp
            from sap_volume_dsp
            join
            (
            -- get equip duplicate with min production
            select lequnr, dateid, [shift], min(prod) as prod from sap_volume_dsp where rtrim(Lequnr) in
            (
                -- get duplicate equip
                select rtrim(lequnr) from
                (
                    select count(lequnr) as jml, Lequnr from sap_volume_dsp group by dateid, lequnr, [shift]
                ) tmp where jml > 1
            ) group by lequnr, dateid, [shift]
            ) tabfilter
            on
            sap_volume_dsp.lequnr = tabfilter.lequnr
            and sap_volume_dsp.dateid = tabfilter.dateid
            and sap_volume_dsp.[shift] = tabfilter.[shift]
            and sap_volume_dsp.prod = tabfilter.prod

Dibawah ini adalah hasil dari script diatas menyisakan hanya 1 baris untuk masing-masing duplicate row.

Remove Duplicate Row Using Query In SQL Server


Semoga posting tentang "Remove Duplicate Row Using Query In SQL Server" diatas dapat bermanfaat.



Salam,


Popular posts from this blog

SmartObject property ID is a required property for selected method Create. Value must be set.

Cara inject USB 3.0 Driver pada instalasi Windows - How to Inject USB 3.0 Driver in Windows 7

Python Font Color in Console