Project

General

Profile

Actions

Anomalie #839

closed

MySQL (recent version) SQL syntax issue on Distinct list queries

Added by Régis over 6 years ago. Updated over 6 years ago.

Status:
Fermé
Priority:
Normal
Assignee:
Category:
general
Target version:
Start date:
04/17/2018
Due date:
% Done:

100%

Estimated time:
2.00 h
Resolution:

Description

We run a recent version of MySQL (5.7) and some queries on SQL_getNewsList were rejected. Some other queries may be affected also

Our patch on www/news/mysql.inc.php SQL_getNewsList is:

-  $q= "SELECT DISTINCT(news_id), LEFT(news_title, 60) AS news_title, news_title AS complete_news_title, ".
+  $q= "SELECT DISTINCT(news_id), ".
+        "news_range, news_date_crea, ".
+        "LEFT(news_title, 60) AS news_title, news_title AS complete_news_title, ".

DISTINCT queries using order by MUST have the order by fields in the select.

Simple example:

mysql> select version();
----------------------- | version() |
----------------------- | 5.7.21-0ubuntu0.16.04.1 |
-----------------------
1 row in set (0,00 sec)
mysql> SELECT DISTINCT, LEFT AS news_title FROM l21_news ORDER BY news_date_crea ASC;
ERROR 3065 (HY000): Expression #1 of ORDER BY clause is not in SELECT list, references column 'xxxxx.l21_news.news_date_crea' which is not in SELECT list; this is incompatible with DISTINCT
mysql> SELECT DISTINCT, news_date_crea, LEFT AS news_title FROM l21_news ORDER BY news_date_crea ASC;
----------------------------+-----------------+ | news_id | news_date_crea | news_title |
----------------------------+-----------------
(...)

Actions

Also available in: Atom PDF