Lets say I have one table called “REVIEWS”
This table has Reviews that customers have written for various products.
I would like to be able to get a “count” for all the reviews that each customer has written, so I write:
SELECT count(*) AS counter FROM reviews WHERE customers_id = 12345
Now, my problem is that I wish to have a count like above BUT only for customers who have written a SPECIFIC product review
For instance,
SELECT customers_review FROM reviews WHERE products_id = '170'
In summary, I wish to be able to get the customers TOTAL COUNT for every review they have written, but ONLY for customers who have written a review for a specific product.
Advertisement
Answer
select customers_id, count(*) from reviews where customers_id in (select customers_id from reviews where products_id = '170') group by customers_id;