ORDER BY clause is not in SELECT list [message #690225] |
Fri, 13 December 2024 10:30 |
Frank Naude
Messages: 4587 Registered: April 1998
|
Senior Member |
|
|
Maybe someone here can help me to rewrite the query below. It was working perfectly in MySQL 5, but after upgrading to MySQL 8, is giving an error:
mysql> SELECT DISTINCT thread_id, subject FROM msg WHERE apr=1 ORDER BY post_stamp DESC LIMIT 10;
ERROR 3065 (HY000): Expression #1 of ORDER BY clause is not in the SELECT list, referencing column 'msg.post_stamp' which is not in the SELECT list; this is incompatible with DISTINCT;
I can easily add 'post_stamp' to the SELECT list, but that will produce a completely different result!
|
|
|
|
Re: ORDER BY clause is not in SELECT list [message #690229 is a reply to message #690227] |
Fri, 13 December 2024 13:27 |
Frank Naude
Messages: 4587 Registered: April 1998
|
Senior Member |
|
|
Problem solved. Thank you Michel!
mysql> SELECT DISTINCT thread_id, subject FROM (SELECT thread_id, subject FROM msg WHERE apr=1 ORDER BY post_stamp DESC LIMIT 30) LIMIT 10;
ERROR 1248 (42000): Every derived table must have its own alias
MySQL is full on nonsense - but, this works:
mysql> SELECT DISTINCT thread_id, subject FROM (SELECT thread_id, subject FROM msg WHERE apr=1 ORDER BY post_stamp DESC LIMIT 50) x LIMIT 10;
+-----------+--------------------------------------------------------------------+
| thread_id | subject |
+-----------+--------------------------------------------------------------------+
| 208718 | Re: New server migration |
| 208719 | Re: ORDER BY clause is not in SELECT list |
| 208717 | Re: Help Needed in Calculation Logic function |
| 208719 | ORDER BY clause is not in SELECT list |
| 208718 | New server migration |
| 208714 | Re: dense_rank() in formula column |
| 208717 | Help Needed in Calculation Logic function |
| 208716 | Re: Find out the column values based on primary key from one table |
| 208716 | Find out the column values based on primary key from one table |
| 208265 | Re: FCBGuard or USB security token login AS SYSDBA |
+-----------+--------------------------------------------------------------------+
|
|
|