Can I use non-aggregate columns with group by?

前端 未结 6 805
不思量自难忘°
不思量自难忘° 2020-12-09 09:24

You cannot (should not) put non-aggregates in the SELECT line of a GROUP BY query.

I would however like access the one of the non-aggregate

6条回答
  •  离开以前
    2020-12-09 10:13

    You have to have a join because the aggregate function max retrieves many rows and chooses the max. So you need a join to choose the one that the agregate function has found.

    To put it a different way how would you expect the query to behave if you replaced max with sum?

    An inner join might be more efficient than your sub query though.

提交回复
热议问题