Well, I'm developing a project and it has the list of people, I would like to list them based on the average of the evaluation, I tried to do with INNER JOIN and AVG, but with them they will not show users who have just registered. The SELECT that works for what I want is this:
SELECT p.idPessoa, p.nomePessoa, p.descricaoPessoa, f.nomeFoto,
(SELECT SUM(a.valorAvaliacao /
(SELECT COUNT(a.idAvaliacao) FROM tb_avaliacao as a
WHERE a.idCategoria = '$idcategoria' && a.idPessoa = '$idpessoa'
GROUP BY a.idPessoa AND a.idCategoria))
FROM tb_avaliacao as a
WHERE a.idCategoria = '$idcategoria' && a.idPessoa = '$idpessoa'
GROUP BY a.idPessoa AND a.idCategoria) as valorAvaliacao
FROM 'tb_pessoa' as p
INNER JOIN tb_pessoacategoria as pc ON pc.idPessoa = p.idPessoa
INNER JOIN tb_foto as f ON pc.idPessoa = f.idPessoa and pc.idCategoria = f.idCategoria
INNER JOIN tb_categoria as c ON c.idCategoria = pc.idCategoria
WHERE c.idCategoria = '$idcategoria'
GROUP BY p.idPessoa
ORDER BY valorAvaliacao DESC, f.idFoto
Is there any way to do the same SELECT only without using the variable $ idpessoa? I need you to have a column that shows the average of the evaluations received, but without using INNER JOIN between tb_people and tb_avaliacao.