I have two tables, lists and globals_lists. A globals_lists basically associates a list_id with a global_id value. I’d like to get a count of global_ids (ie the number of ‘manys’ in the globals_lists table) for the associated list type for each user.
something like:
select l.id, l.user_id, count(gl.global_id) as gl_count
from lists l, globals_lists gl
where l.list_type_id=10 and l.id=gl.list_id;
but this is giving me back wrong information.
Add:
after your
whereclause.Without
GROUP BY, you are basically just counting up all rows that meet theWHEREand join conditions without any regard to set grouping.GROUP BYwill ensure that you are performing the count aggregation per user -> list combination.