MySQL Distinct Records With Count

I have a photo table with two columns in this table with the names "id" and "user_id". Obviously, one user can have many photos. I would like to run a query that can give me the number of photos for each user.

Any help is appreciated.

+3
source share
3 answers
select user_id, count(*) as photo_count from photos group by user_id
+8
source

Using:

SELECT t.user_id,
       COUNT(*) AS photo_count
  FROM PHOTOS
GROUP BY t.user_id
+3
source

count groupby, ,

:

SELECT user_id, count(*) 'Photos Count'
from photos
group by user_id
0

Source: https://habr.com/ru/post/1751492/


All Articles