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

เกี่ยวกับ ปัญหาการใช้งาน การติดตั้ง ฐานข้อมูล MySql Oracle MSSQL ect...
การเขียน คำสั่ง SQL เพื่อดึกข้อมูล บอร์ดนี้ควรระบุโครงสร้างตารางของท่านในคำถามด้วยนะ

Moderator: mindphp

ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41230
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

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

โพสต์ที่ยังไม่ได้อ่าน โดย 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 
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41230
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

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

โพสต์ที่ยังไม่ได้อ่าน โดย 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
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 47