How to resolve “ORDER BY clause is not in SELECT list” caused MySQL 5.7 with SELECT DISTINCT and ORDER BY

前端 未结 8 812
故里飘歌
故里飘歌 2020-12-29 20:21

I installed the new Ubuntu and my code has got a problem with MySQL.

( ! ) Warning: PDOStatement::execute(): SQLSTAT         


        
相关标签:
8条回答
  • 2020-12-29 20:36

    This worked for me that @pvgoran suggested

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

    You can run this when you want.

    0 讨论(0)
  • 2020-12-29 20:37

    If you have phpMyAdmin:

    1-go to the Variables tabs

    2-search label "sql mode"

    3-edit the content and delete the mode : "ONLY_FULL_GROUP_BY"

    4-save

    NB: don't forget to verify the comma separator

    0 讨论(0)
  • 2020-12-29 20:43

    You can run as said :

    SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
    SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
    
    0 讨论(0)
  • 2020-12-29 20:44

    With MAMP PRO

    You cannot edit your my.cnf file directly. You must use the MAMP PRO interface to edit your my.cnf file. In the menu go to File > Edit Template > MySQL > my.cnf. Then add sql_mode='' under the [mysqld] key

    0 讨论(0)
  • 2020-12-29 20:49

    In order to fix the issue open the following file:

    /etc/mysql/mysql.conf.d/mysqld.cnf
    

    and add the following line under [mysqld] block

    sql-mode=""
    
    0 讨论(0)
  • 2020-12-29 20:50

    To get ->distinct('some_column') to work for me, I needed to disable ONLY_FULL_GROUP_BY option in mysql modes.

    Rather than edit the mysql config file on the filesystem, I followed the instructions at Laravel : Syntax error or access violation: 1055 Error and added this to config/database.php:

            'strict' => true,
            'modes' => [
                // 'ONLY_FULL_GROUP_BY', // disabled to allow grouping by one column
                'STRICT_TRANS_TABLES',
                'NO_ZERO_IN_DATE',
                'NO_ZERO_DATE',
                'ERROR_FOR_DIVISION_BY_ZERO',
                'NO_AUTO_CREATE_USER',
                'NO_ENGINE_SUBSTITUTION'
            ],
    

    In my project, the modes property was non-existent, so I simply pasted that bad boy in there.

    NOTE: Make sure you understand that wiping the modes entirely is undesirable, and basically not strict mode, so you will lose debugging warning/error messages about stuff like varchar length exceeded. The trick is to avoid sql_mode="". Notice how above I am using 6 modes and explicitly omitting ONLY_FULL_GROUP_BY.

    0 讨论(0)
提交回复
热议问题