views:

26

answers:

2

I have a photos table, with two columns in that table 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.

+4  A: 
select user_id, count(*) as photo_count from photos group by user_id
tschaible
+1: You were first
OMG Ponies
Thank you. I am an idiot!
speric
+1  A: 

Use:

SELECT t.user_id,
       COUNT(*) AS photo_count
  FROM PHOTOS
GROUP BY t.user_id
OMG Ponies
+1: for also getting it right, worked great
JohnB