我需要获取列中具有重复值的行。这是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 :(得分: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`