Is the order of union all guaranteed?

Asked 1 years ago, Updated 1 years ago, 37 views

When using UNION ALL in MySQL, if there is no ORDER BY, the elements will basically return in the order of UNION.

Question

  • Can I expect the UNION ALL set to return elements in the order of UNION as MySQL or SQL specifications?

  • Or, if certain conditions (storage engine, etc.) are met, will each element of UNION ALL be acquired in a mix?

As a MySQL or SQL specification, can I expect UNION ALL sets to return elements in the order of UNION?

Or, if certain conditions (storage engine, etc.) are met, will each element of UNION ALL be acquired in a mix?

mysql sql

2022-09-30 19:48

1 Answers

The MySQL reference does not have an order guarantee, so I don't think it's guaranteed.You should add ORDER BY.
(No matter how many times you test it, you often get good results.)


2022-09-30 19:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.