Search code examples
mysqlprocedure

MySql 5.7.18 error in Group by clause with sql_mode=only_full_group_by


I am on Ubuntu Server 16.xx with MySql version 5.7.18,

I have the following query:

 SELECT DISTINCT 
    w.sno,
    CONCAT(
      CONCAT(
       (SELECT 
          bch_lbl 
        FROM
          list_benches 
        WHERE sno = w.lb_sno),
          ' => ',
          CASE
            WHEN w.bench_cat_sno = 0 
            THEN 'All Categories' 
          ELSE 
            (SELECT 
               cat_name 
            FROM
               case_categories 
            WHERE sno = w.bench_cat_sno) 
         END,
          ' [From ',
            b.date_from,
          ' To ',
          b.date_to,
           '] '
         ),
     CASE
        WHEN b.is_active = 1 
     THEN 'Active' 
     ELSE 'Expired' 
    END
      ) AS benchLbl,
        w.is_active,
        b.j_sno 
  FROM
      working_benches w,
      bench_judges b 
  WHERE w.sno = b.b_sno 
  GROUP BY w.sno 
  ORDER BY b.is_active DESC ;

after execution, this query return the following error:

Error Code: 1055
Expression #2 of SELECT list is not in GROUP BY clause and contains 
nonaggregated column 'phc_caseflow.b.date_from' which is not functionally 
dependent on columns in GROUP BY clause; this is incompatible with 
sql_mode=only_full_group_by

The only thing i have understood is "sql_mode=only_full_group_by" which become cause of the above error.

Can anybody suggest me how to change the above query to fit into and fix the problem - need to edit my query only not the sql_mode:

thanks in advance...


Solution

  • After review all the Logs file and google the problem, i find that this is a "BIG" update in MySql Version minor version i.e v 5.7.18. So, the solution i have find was to do the following shortcut:

    sudo nano /etc/mysql/my.cnf
    Add this to the end of the file
    
    [mysqld]  
    sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
    

    And my queries running very good on server, i mean on my production server...