I'm having a problem in a select where I need to get the data from 3 tables (search, users, and query_research). Where search_response can or does not have data. The current query is:
SELECT
usuarios.nome AS nome_autor,
pc_pesquisa.*,
COUNT(pc_resposta_pesquisa.id) AS respostas
FROM pc_pesquisa
LEFT JOIN usuarios
ON usuarios.id = pc_pesquisa.id_autor
LEFT JOIN pc_resposta_pesquisa
ON pc_resposta_pesquisa.id_pesquisa = pc_pesquisa.id
WHERE pc_pesquisa.id_tipo = 1 ORDER BY pc_pesquisa.data ASC
The data from the pc_earch and user tables return ok, but only returns the searches that have registered responses. It is necessary to return even if there is no (null or zero).
I currently have 2 searches registered, one with 4 replies and one with 0 replies. This query only returns the search that has answers.