2014-04-04 43 views
0

我需要获取在列中具有重复值的行。这是SQL:如何获得具有更好性能的重复值的行

select * from `match` where `match`.`homeTeam` in 
(select `matchView`.`homeTeam` from `matchView` 
group by `matchView`.`homeTeam` having (count(0) > 1)) 
order by `match`.`homeTeam` 

它完成这项工作,但需要15秒。我能做些什么来提高它的速度

编辑:解释SQL结果:

id select_type  table type possible_keys key  key_len  ref  rows Extra 
1 PRIMARY  match ALL  NULL NULL NULL NULL 2691 Using where; Using filesort 
2 DEPENDENT SUBQUERY match ALL  NULL NULL NULL NULL 2691 Using where; Using temporary; Using filesort 
+0

您可以加入'exaplain'结果和表结构? –

+0

你已经在列中有索引了吗? –

+0

@dragoste我在phpmyadmin中添加了解释sql,如果这是你问的 – user3354638

回答

0
select `match`.* 
from `match` join (select `matchView`.`homeTeam` 
        from `matchView` 
        group by `matchView`.`homeTeam` 
        having (count(0) > 1)) watches ON `match`.`homeTeam`=watches.`homeTeam` 
order by `match`.`homeTeam` 
+0

哇!与0.07秒相同的结果。不知道连接是如此有用。不赞成投赞成票。 – user3354638

相关问题