Group bY not in select

  • Is there anyway to group by a column not in the select list?

  • Use GROUP BY and you column even if not in the select list is fine. Just keep in mind anything not in an Aggregate function such as SUM, MAX, MIN, AVG and so on will also have to by in the GROUP BY clause for it to work.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • It is perfectly alright to group by a field which is not in the select list but all the fields in the select list should either be in an aggregate function or in group by list.

    This will not work:

    select city from authors group by state

    This will work:

    select city from authors group by state, city

    select state, count(city) from authors group by state

    Give me a fish, you feed me for a day! Teach me to fish, you feed me for a life time.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply