How I select all records from the table

Asked

Viewed 45 times

0

How do I select all records in select below:

$select = "SELECT COUNT(1) AS id_mark, SUM(a.rate) AS rate, b.name_mark, b.id 
           FROM tb_comment a, tb_mark b 
           WHERE a.id_mark=b.id AND b.id_category=:id_c 
           GROUP BY a.id_mark, b.name_mark 
           ORDER BY rate DESC 
           LIMIT $start_pg, $amount_pg";

Why on this SELECT is just selecting the 'items' that has some value in 'rate', there would be no way to select everything and those that do not have value to show '0' as value?

On the table tb_mark has all entries*[topics]* and in the table tb_comment has all the records of comments from topics, and select is only displaying the entries that have some record in the table tb_comment.

1 answer

1


So it takes all the rows of the table

SELECT id_mark, COALESCE(a.rate, 0) AS rate, b.name_mark, b.id FROM tb_comment a, tb_mark b WHERE a.id_mark=b.id AND b.id_category=:id_c ORDER BY rate DESC

Browser other questions tagged

You are not signed in. Login or sign up in order to post.