简体   繁体   中英

MySQL - Checking for multiple entries with multiple columns

i wanna delete multiple entries on my table which have 3 columns the same (they should only exist once)

Lets say:

Table_Users

4 columns - country - city - house - name

So i just want to have only one entry with counry, city and name the same.

If there are more entries with country, city and name the same, it should delete the others.

delete from Table_Users a
where exists (select b.idx from Table_Users b 
              where b.idx < a.idx and
                    b.country = a.country and
                    b.city = a.city and
                    b.name = a.name)

You need a unique reference field, I have called it idx . It deletes and entry when the 3 fields match and an earlier one exists.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM