When MySQL's only_full_group_by
mode is turned on, it means that strict ANSI SQL rules will apply when using GROUP BY
. With regard to your query, this means that if you GROUP BY
of the proof_type
column, then you can only select two things:
proof_type
column, or
By "aggregates" of other columns, I mean using an aggregate function such as MIN()
, MAX()
, or AVG()
with another column. So in your case the following query would be valid:
SELECT proof_type,
MAX(id) AS max_id,
MAX(some_col),
MIN(some_other_col)
FROM tbl_customer_pod_uploads
WHERE load_id = '78' AND
status = 'Active'
GROUP BY proof_type
The vast majority of MySQL GROUP BY
questions which I see on SO have strict mode turned off, so the query is running, but with incorrect results. In your case, the query won't run at all, forcing you to think about what you really want to do.
Note: The ANSI SQL extends what is allowed to be selected in GROUP BY
by also including columns which are functionally dependent on the column(s) being selected. An example of functional dependency would be grouping by a primary key column in a table. Since the primary key is guaranteed to be unique for every record, therefore the value of any other column would also be determined. MySQL is one of the databases which allows for this (SQL Server and Oracle do not AFAIK).