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

前端 未结 19 3039
灰色年华
灰色年华 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:56

    Open you WAMP panel and open MySQL configuration file. In it search for "sql_mode" if you find it set it to "" else if you don't find it add sql_mode="" to the file.

    Restart the MySQL server and you are good to go...

    happy coding.

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

    When MySQL's only_full_group_by mode is turned on, it means that strict ANSI SQL rules will apply when using GROUP BY. With regard to your query, this means that if you GROUP BY of the proof_type column, then you can only select two things:

    • the proof_type column, or
    • aggregates of any other column


    By "aggregates" of other columns, I mean using an aggregate function such as MIN(), MAX(), or AVG() with another column. So in your case the following query would be valid:

    SELECT proof_type,
           MAX(id) AS max_id,
           MAX(some_col),
           MIN(some_other_col)
    FROM tbl_customer_pod_uploads
    WHERE load_id = '78' AND
          status = 'Active'
    GROUP BY proof_type
    

    The vast majority of MySQL GROUP BY questions which I see on SO have strict mode turned off, so the query is running, but with incorrect results. In your case, the query won't run at all, forcing you to think about what you really want to do.

    Note: The ANSI SQL extends what is allowed to be selected in GROUP BY by also including columns which are functionally dependent on the column(s) being selected. An example of functional dependency would be grouping by a primary key column in a table. Since the primary key is guaranteed to be unique for every record, therefore the value of any other column would also be determined. MySQL is one of the databases which allows for this (SQL Server and Oracle do not AFAIK).

    0 讨论(0)
  • 2020-11-22 12:01
    > sudo nano /etc/mysql/my.cnf
    

    Enter below

    [mysqld]
    sql_mode = ""
    

    Ctrl + O => Y = Ctrl + X

    > sudo service mysql restart
    
    0 讨论(0)
  • 2020-11-22 12:04

    go to the phpmyadmin and open the console and execute this request

    SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
    
    0 讨论(0)
  • 2020-11-22 12:04

    I had similar problem with part of my database crushing. What I did is I changed the parameter in the DB via PHPStorm database console like this:

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

    works like charm now

    0 讨论(0)
  • 2020-11-22 12:05

    In Ubuntu

    Step 1:

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

    Step 2: Go to last line and add the following

    sql_mode = ""
    

    Step 3: Save

    Step 4: Restart mysql server.

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