How to display results if my select gives false?

0

And I'm having the following problem, there are two tables POSTS and TOPICS, one topic has several posts, and I'm displaying the topics ordering by the most current date of the post of the topic, only that when creating a new topic it does not display in the screen because it has no post, and if I post in the topic it displays on the screen because it has post, and I wanted to know how can I display the topics that have no posts? How can I list the topics that have no posts? Because my JOINN is only bringing the topics that have related posts

$sqlTopicos = mysqli_query($conexao, 
        "SELECT topico.titulo, posts.idTopico, slug, posts.dataPost, usuario.usuario, visualizacoes, qtdPosts 
         FROM (SELECT * FROM posts ORDER BY dataPost DESC) posts 
         INNER JOIN topico 
            ON posts.idTopico = topico.idTopico
         INNER JOIN usuario
            ON topico.idUsuario = usuario.idUsuario
         WHERE posts.idArea = '$idArea' GROUP BY titulo ORDER BY posts.dataPost DESC");
    
asked by anonymous 12.11.2016 / 18:59

1 answer

0

Make a Left Join between the tables: link . It will bring the results of Topicos even if there are no associated Posts.

Example:

SELECT * FROM Topicos t
LEFT JOIN Posts p
ON t.TopicoID=p.TopicoID
ORDER BY t.DataCriacao;
    
12.11.2016 / 19:12