หน้า 1 จากทั้งหมด 1

ปัญหา Error GROUP BY clause; this is incompatible with sql_mode=only_full_group_by [1055]

โพสต์แล้ว: 19/07/2019 7:30 pm
โดย mindphp
which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by [1055]

เกิดจาก การใช้คำสั่ง

โค้ด: เลือกทั้งหมด

SELECT * FROM table Group BY id 
ซึ่ง MySQL 5.7 default config จะไม่สามารถใช้คำสั่งแนวนี้ได้

ถ้าเราอยากได้ค่าไม่ซ้ำ อยาจใน คำสั่ง DISTINCT

โค้ด: เลือกทั้งหมด

SELECT  DISTINCT id FROM table 

Re: ปัญหา Error GROUP BY clause; this is incompatible with sql_mode=only_full_group_by [1055]

โพสต์แล้ว: 22/07/2019 5:48 am
โดย mindphp
จาก Error
Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'tablename.a.anonymous_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by [1055]
ถ้าต้องการแก้ไข ที่ config ของ MySQL สามารถทำได้ดังนี้

เข้า phpMyAdmin ในฐานะ user root
รันคำสั่ง SQL

โค้ด: เลือกทั้งหมด

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

(ไม่ต้อง Restart MySQL)

อีกวิธี คือ แก้ไข my.cnf

โค้ด: เลือกทั้งหมด

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
save และ restart MySQL