I want to display all rows of table article
, and for each of article row i want get the SUM
of votes
from another table (likes
), and this with one query.
Here what i have:
$query = "SELECT article.title,article.tags,article.description,article.slug,users.username,article.photo,article.id,article.date,SUM(likes.votes) as upvotes
FROM article";
$query .= " LEFT JOIN users ON article.user_id = users.user_id ";
$query .= " LEFT JOIN likes ON likes.article_id = article.id ";
But my problem with this query, i get only one row ! because in table likes
there only one row ...
I want to display results based on article
table (i have about 50 rows in it)... and if there nothing related to votes for a specific article, we show (0 votes).
Thank you.