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

前端 未结 8 813
故里飘歌
故里飘歌 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:57

    If you have control of the server and you are running legacy code you can't easily change, you can adjust the SQL mode of the server and remove "only_full_group_by" either for the duration of boot, by running the query

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

    or by adding sql_mode='' to your my.cnf file.

    Obviously its better to change your code if you have the possibility, but if not, this will disable that warning.

    0 讨论(0)
  • 2020-12-29 21:00

    Try this:

        SELECT p.products_id,  p.products_price  
          FROM :table_products p
     LEFT JOIN :table_specials s on p.products_id = s.products_id 
         WHERE
               products_status = :products_status AND
               products_view = :products_view AND
               p.products_archive = :products_archive
      ORDER BY rand(),  p.products_date_added DESC
      GROUP BY p.products_id,p.products_price 
         LIMIT :products_limit
    
    0 讨论(0)
提交回复
热议问题