SELECT list is not in GROUP BY clause and contains nonaggregated column … incompatible with sql_mode=only_full_group_by

前端 未结 19 3036
灰色年华
灰色年华 2020-11-22 11:28

AM using MySQL 5.7.13 on my windows PC with WAMP Server

Here my Problem is While executing this query

SELECT *
FROM `tbl_customer_pod_uploads`
WHERE          


        
相关标签:
19条回答
  • 2020-11-22 11:38

    You can disable sql_mode=only_full_group_by by some command you can try this by terminal or MySql IDE

    mysql> set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
    
    mysql> set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
    
    0 讨论(0)
  • 2020-11-22 11:38

    From how it looks, I think grouping by multiple columns/fields wont hurt your result. Why don't you try adding to the group by like this:

    GROUP BY `proof_type`, `id`
    

    This will group by proof_type first then id. I hope this does not alter the results. In some/most cases group by multiple columns gives wrong results.

    0 讨论(0)
  • 2020-11-22 11:41

    Here is a really fast and easy way of setting it permanently

    NB: running SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); is temporary and on server restart you will still end up with the error. To fix this permanently do the below

    1. Login to your server as root
    2. in your terminal run wget https://gist.githubusercontent.com/nfourtythree/90fb8ef5eeafdf478f522720314c60bd/raw/disable-strict-mode.sh
    3. Make the script executable by running chmod +x disable-strict-mode.sh
    4. Run the script by running ./disable-strict-mode.sh

    And your done , changes will be made to mysql and it will be restarted

    0 讨论(0)
  • 2020-11-22 11:42

    This

    Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'returntr_prod.tbl_customer_pod_uploads.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

    will be simply solved by changing the sql mode in MySQL by this command,

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

    This too works for me.. I used this, because in my project there are many Queries like this so I just changed this sql mode to only_full_group_by

    Thank You... :-)

    0 讨论(0)
  • 2020-11-22 11:42

    Hi instead of taking all columns, just take what you need by using ANY_VALUE(column_name). It is working perfectly. Just check.

    E.g.:

    SELECT proof_type,any_value("customer_name") as customer_name
    FROM `tbl_customer_pod_uploads`
    WHERE `load_id` = '78' AND `status` = 'Active' GROUP BY `proof_type`
    
    0 讨论(0)
  • 2020-11-22 11:43
    1. Login to phpMyAdmin
    2. Navigate to : Server: localhost:3306 and do not select any database
    3. Click on variables from the top menu
    4. Search for "sql mode" and edit the corresponding value to : NO_ENGINE_SUBSTITUTION

    That's all.

    I did this in my Ec2 and it worked like charm.

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