Mysql 如何以更好的性能获取具有重复值的行
我需要获取列中具有重复值的行。这是SQL:Mysql 如何以更好的性能获取具有重复值的行,mysql,sql,Mysql,Sql,我需要获取列中具有重复值的行。这是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结果:
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
你能添加
exaplane
result和tables结构吗?你在列中已经有索引了吗?@dragoste我在phpmyadmin上添加了explain sql,如果你是这样问的话!相同的结果为0.07秒。我不知道加入这么有用。对不起,我不能投票。
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`