0
Good night,
I am trying to make a Join to 5 tables to fetch me the information so that it is not returning me some data.
Code
SELECT * FROM estabelecimentos
INNER JOIN estabelecimentos_anexos
ON estabelecimentos_anexos.id_mae = estabelecimentos.id
INNER JOIN (SELECT COUNT(*) AS id FROM avaliacoes)
ON avaliacoes.estabelecimento_id = estabelecimentos.id
INNER JOIN (SELECT COUNT(*) AS id FROM estabelecimentos_anexos)
ON estabelecimentos_anexos.id_mae = estabelecimentos.id
INNER JOIN (SELECT COUNT(*) AS id_post FROM posts)
ON posts.estabelecimento_id = estabelecimentos.id
INNER JOIN (SELECT ROUND((SUM(pontos) / COUNT(*)), 1) FROM avaliacoes)
ON avaliacoes.estabelecimento_id = estabelecimentos.id
WHERE estabelecimentos.activo = 1
What is the structure of your tables? Have you considered setting an example on Sqlfiddle? Anyway, I believe that [one of] your problem is that the Subqueries used are not earning a nickname so that they can be referenced in the
ON
(more details that question in Soen).– mgibsonbr