- 使用select * from 表 group by 字段 時報錯
錯誤信息說明:
1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'haha_db.staff.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
- 只需要執行下面的SQL語句來更改sql mode即可
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY',''));
注意在執行上述語句后需要重新連接數據庫
- 重新建立連接后再次執行SQL語句,顯示執行成功
說明:group by默認顯示的是每一組找到的第一條信息