Mysql Query to delete duplicates -


i have duplicate results below column may have data , may not

| contact_info | icon | id  | title         | lastmodified_by  | +--------------+------+-----+---------------+------------------+ |          169 |  305 | 123 | whakarewarewa | 2011100400305262 | |         null | null | 850 | whakarewarewa | null             | +--------------+------+-----+---------------+----------------    | contact_info | icon | id  | title         | lastmodified_by  | +--------------+------+-----+---------------+------------------+ |         null | null | 123 | paris         | null             | |         null | null | 850 | paris         | null             | +--------------+------+-----+---------------+---------------- 

i want delete record having less data , if field values exact same delete row. there thousand records this.

try two-step solution:

run query vew duplicates - record having less data -

select t1.* table t1   join (     select       title,       min(if(contact_info null, 0, 1) + if(contact_info null, 0, 1) + if(lastmodified_by null, 0, 1)) min_value_data,       max(if(contact_info null, 0, 1) + if(contact_info null, 0, 1) + if(lastmodified_by null, 0, 1)) max_value_data     table group title having min_value_data <> max_value_data   ) t2   on t1.title = t2.title , if(t1.contact_info null, 0, 1) + if(t1.contact_info null, 0, 1) + if(t1.lastmodified_by null, 0, 1) <> t2.max_value_data 

rewrite delete statement , execute.


then run query remove duplicates except min id:

delete t1 table t1   join (select min(id) id, title table group title) t2     on t1.id <> t2.id , t1.title = t2.title; 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -