Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


MySQL count query help

Posted on 2014-07-14
Medium Priority
Last Modified: 2014-07-14
Hi All,

I have a MySQL table where users have rated movies 1-5.  I want to get a summary of how  man 1,2,3,4 & 5's they have voted for.

I can get the answer for a single rating, below

SELECT COUNT(rating) AS "1 Star" FROM user_likes WHERE user_id=2 AND rating=1

Is it possible to get them all at in one go?
Question by:detox1978
LVL 21

Accepted Solution

Randy Poole earned 2000 total points
ID: 40195264
SELECT COUNT(rating) AS num,rating FROM user_likes WHERE user_id=2  group by rating

Author Closing Comment

ID: 40195282
Excellent thanks
LVL 12

Expert Comment

by:Nathan Riley
ID: 40195284
select count(rating) AS NumofVotes, rating
from user_likes WHERE user_id=2
group by rating
order by rating desc

Open in new window


Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question