fightstarr20
fightstarr20

Reputation: 12598

SQL Table return number of items with review number ID

I have a SQL table which has reviews saved like this....

SQL Database Example

I am looking to return the amount of reviews listed for a certain ID number. The table itself is called gg_reviews

I know this is real simple but for some reason its baffling me, can someone help?

Upvotes: 0

Views: 44

Answers (3)

Michael Grenzer
Michael Grenzer

Reputation: 501

kk.. can't find there a way to see where you store the id.. but i would "suggest" the following:

SELECT ID, COUNT(ID) as views FROM gg_reviews GROUP BY ID

Upvotes: 0

PHeiberg
PHeiberg

Reputation: 29811

You don't say which ID you want to count reviews for, but provided that it's the page_id:

SELECT page_id, COUNT(*) as totalReviews
FROM gg_reviews
GROUP BY page_id

Upvotes: 0

Taryn
Taryn

Reputation: 247680

Unless I am missing something, you just need to COUNT() and GROUP BY. The GROUP BY field should be the unique value for each page.

SELECT count(*) as TotalReview, ID  -- change ID to the unique id for the page
FROM gg_reviews
GROUP BY ID  -- change ID to the unique id for the page

Upvotes: 2

Related Questions