create table test.tmp_is_primary_phone ( id integer unsigned ); insert into test.tmp_is_primary_phone select min(id) from civicrm_phone where is_primary = 1 group by contact_id ; update civicrm_phone set is_primary = 0 where id not in ( select id from test.tmp_is_primary_phone ) ; drop table test.tmp_is_primary_phone ; -- or ... but this doesn't work (yet) UPDATE civicrm_email SET is_primary=0 WHERE id NOT IN ( SELECT MIN(id) FROM civicrm_email WHERE is_primary=1 GROUP BY contact_id ) ;