[英]Strange behavior in mySQL 8 with order by, limit and parentheses
[英]MySQL - Strange behavior in subquery with LIMIT / ORDER BY
我面臨一個奇怪的問題:
select * from (
select id from myTable1 limit 10
) t1
union
select * from (
select id from myTable2 limit 10
) t2
=> Return 20 rows
select * from (
select id from myTable1 limit 10 ORDER BY id
) t1
union
select * from (
select id from myTable2 limit 10
) t2
=> Return 10 rows
如您所見,這兩個查詢之間的唯一區別是第一個子查詢中的“ order by”。
是一個錯誤還是我在這里錯過了一些東西?
更多信息:
> SHOW VARIABLES LIKE "%version%";
innodb_version 5.6.16
protocol_version 10
slave_type_conversions
version 5.6.16
version_comment MySQL Community Server (GPL)
version_compile_machine x86_64
version_compile_os Win64
這是由於一個簡單的錯誤:
ORDER BY
和LIMIT
被交換:
(
select id from myTable1 ORDER BY id limit 10
)
union
(
select id from myTable2 limit 10
)
=> return 20 rows
如注釋中所建議,最好使用UNION ALL
但我的2個數據集沒有共同的數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.