Question

I am displaying the list of games and using left join table review.
I need to just take the total reviews of each game to have an output:

array (
[0] => array ('title' => 'game1', 'reviews' => 0), 
[1] => array ('title' => 'game2', 'reviews' => 2), 
[2] => array ('title' => 'game3', 'reviews' => 0), 
) 

I'm having trouble mounting the sql

my sql

select A.title, review.text from game as A
left join game_review as review on review.id_game = A.id
limit 5

my db

tbl-games [id, title]
game1
game2
game3

tbl-review [id, id_game, text]
review of game2
review of game2
Was it helpful?

Solution

This will do the Job i think

select game.title, count(game_review.text) from game_review, game where game.id = game_review.id 

or

select game.title, count(review.text) from game 
left join game_review on game.id = game_review.id_game
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top