mysql - SQL: Finding totals from a joined table -
ok, have 2 tables in mysql, photos
, views
. each time photo viewed, new row created in views
.
i want sql homecoming list of photos, total number of views each photo.
i've been trying query, giving me 1 photo result.
select photos.id, photos.loc, count(views.id) views photos left outer bring together views on views.id=photos.id
can explain me doing wrong?
thanks.
you need count
views , group by
photo:
select photos.id, photos.loc, count(*) total_views photos left outer bring together views on views.id = photos.id grouping photos.id, photos.loc
mysql sql
No comments:
Post a Comment