Is order in a subquery guaranteed to be preserved?

后端 未结 3 1164
孤城傲影
孤城傲影 2020-12-10 04:11

I am wondering in particular about PostgreSQL. Given the following contrived example:

SELECT name FROM
  (SELECT name FROM people WHERE age >= 18 ORDER BY         


        
3条回答
  •  温柔的废话
    2020-12-10 04:25

    The are not guaranteed to be in the same order, though when you run it you might see that it is generally follows the order.

    You should place the order by on the main query

    SELECT name FROM
    (SELECT name FROM people WHERE age >= 18) p
    ORDER BY p.age DESC LIMIT 10
    

提交回复
热议问题