D
D
di8822102018-05-28 22:08:57
MySQL
di882210, 2018-05-28 22:08:57

Why doesn't MYSQL double sort work?

Query like (example):
SELECT * FROM
(SELECT * FROM `table` ORDER BY `date` DESC LIMIT 8) a
ORDER BY `price`
sorts by price only (2nd parameter `price` ) ignoring sorting by date (1 parameter date ). How to make it work. Rather, it works on one hosting on another only by the 2nd parameter sorting occurs. Hosters say the problem is in the request.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2018-05-28
@di882210

Because MySQL does not guarantee to preserve the order of the rows retrieved from the subquery.

SELECT * 
  FROM (
    SELECT * 
      FROM `table` 
      ORDER BY `date` DESC 
      LIMIT 8
  ) AS `a`
  ORDER BY `date` DESC, `price`

O
Oleg, 2018-05-28
@402d

so why don't you want
SELECT * FROM `table` ORDER BY `date` DESC,`price` ASC LIMIT 8
?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question