1. 程式人生 > 其它 >Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column

Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column

技術標籤:資料庫

執行報錯:

Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘test.dept_emp.emp_no’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

解決方法:

在Navicat下執行下面語句,重新開啟即可成功。

SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))

原因

MySQL5.7.5及以上預設啟用了ONLY_FULL_GROUP_BY
SQL模式,也就是依賴檢測功能。MYSQL將拒絕選擇列表,這時HAVING條件或ORDER BY查詢出的資料會被認為是未命名的非集合列。