sql - Optimizing mysql query to find all duplicate entries -


i running query this:

select distinct `tablea`.`field1`,                 `tablea`.`filed2` field2alias,                 `tablea`.`field3`,                 `tableb`.`field4` field4alias,                 `tablea`.`field6` field6alias (`tablec`) right join `tablea` on `tablec`.`idfield` = `tablea`.`idfield` join `tableb` on `tableb`.`idfield` = `tablea`.`idfield` , tablea.field2 in   (select field2    tablea    group tablea. having count(*)>1) order tablea.field2 

this find duplicate entries, it's taking lot of time execution. suggestions optimization?

it looks trying find duplicates on field2 in tablea. first step move in subquery from clause:

select distinct a.`field1`, a.`filed2` field2alias,        a.`field3`, b.`field4` field4alias, a.`field6` field6alias  tablea left join      tablec c      on c.`idfield` = a`.`idfield` join      `tableb` b      on b.`idfield` = a.`idfield` join      (select field2        tablea       group field2        having count(*) > 1      ) asum      on asum.field2 = a.field2 order tablea.field2 

there may additional optimizations, hard tell. question "find duplicates" , query "join bunch of tables , filter them" don't quite match. helpful know tables have indexes , unique/primary keys.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -