MySQL Distinct Records With Count
I have a photos table, with two columns in that tab开发者_StackOverflowle named "id" and "user_id". Obviously one user can have many photos. I'd like to run a query that can give me the photo count for each user.
Any help is appreciated.
select user_id, count(*) as photo_count from photos group by user_id
Use:
SELECT t.user_id,
COUNT(*) AS photo_count
FROM PHOTOS
GROUP BY t.user_id
use count as your aggregate function and groupby clause to give the count of specific attribute,
here is the sample:
SELECT user_id, count(*) 'Photos Count'
from photos
group by user_id
精彩评论