[Resolvido] MySql COUNT com WHERE, o count é lento
select t1.id, (select count(campo) from tabela2 where id = t1.id)
from tabela1 t1
where .......
select t1.id, (select count(t2.campo) from tabela2 t2 inner join tabela1 on tabela1.id = t2.id where t2.id = t1.id)
from tabela1 t1
where .......
select t1.id, count(t2.campo)
from tabela1 t1
left join tabela t2 on t2.id = t1.id
where .......
Estou tentando dessas 3 formas e a única que roda é a segunda...mesmo assim, com muita lentidão...
Existe alguma outra melhor forma de montar essa query?
Discussão (5)
Carregando comentários...