Home > Database > Mysql Tutorial > How to Fix MySQL's 'SELECT List Incompatible with GROUP BY' Error?

How to Fix MySQL's 'SELECT List Incompatible with GROUP BY' Error?

Barbara Streisand
Release: 2025-01-04 12:20:36
Original
178 people have browsed it

How to Fix MySQL's

Resolving "SELECT List Incompatible with GROUP BY" Error with SQL_MODE

MySQL's error message:

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'returntr_prod.tbl_customer_pod_uploads.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

indicates that the SELECT list contains non-aggregated columns that are not in the GROUP BY clause. This error occurs when using MySQL's only_full_group_by SQL mode.

Potential Solutions:

  • Change SQL Mode:

You can temporarily disable the only_full_group_by mode by executing the following command:

SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
Copy after login
  • Modify Query:

Alternatively, you can modify your query to include all columns from the SELECT list in the GROUP BY clause:

SELECT *
FROM `tbl_customer_pod_uploads`
WHERE `load_id` = '78' AND
      `status` = 'Active'
GROUP BY `load_id`, `bill_id`, `latitude`, `langitude`, `proof_type`, `document_type`, `file_name`, `is_private`, `status`, `createdon`, `updatedon`
Copy after login
  • Use Aggregator Functions:

For best practices in Structured Query Language, avoid selecting all columns. Instead, use aggregator functions on the grouping columns, such as:

SELECT MAX(`id`) AS `id`,
       COUNT(*) AS `total_rows`
FROM `tbl_customer_pod_uploads`
WHERE `load_id` = '78' AND
      `status` = 'Active'
GROUP BY `load_id`
Copy after login

The above is the detailed content of How to Fix MySQL's 'SELECT List Incompatible with GROUP BY' Error?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template