I have a cadre of craftsmen with about 90 thousand records. I created the SQL below to return me the total of artisans in each of the regions that they are registered. Although it works, it is slow, taking more than 30 seconds to return the records.
How can I improve?
SELECT
coordenacao.descricao AS nome,
COUNT(artesao.codigo) AS qtde
FROM
municipio, artesao, coordenacaomunicipios, coordenacao
WHERE
artesao.codMunicipio = municipio.codigo AND
coordenacaomunicipios.codMunicipio = municipio.codigo AND
coordenacaomunicipios.codCoordenacao = coordenacao.codigo AND
artesao.codStatus = 1
GROUP BY
coordenacao.descricao
ORDER BY
coordenacao.codigo