mysql 为什么子查询不支持limit ,而子查询的子查询 支持 limit
发布网友
发布时间:2022-04-07 20:49
我来回答
共2个回答
热心网友
时间:2022-04-07 22:18
子查询支持的啊, 你怎么写的?
mysql> SELECT * FROM test_main;
+----+-------+
| id | value |
+----+-------+
| 1 | ONE |
| 2 | TWO |
| 3 | THREE |
+----+-------+
3 rows in set (0.00 sec)
mysql> SELECT
-> *
-> FROM
-> (
-> SELECT
-> *
-> FROM
-> test_main
-> ORDER BY
-> id DESC
-> LIMIT 0, 2
-> ) subQuery
-> ORDER BY id
-> LIMIT 0, 1;
+----+-------+
| id | value |
+----+-------+
| 2 | TWO |
+----+-------+
1 row in set (0.00 sec)
追问谢谢了!!!
热心网友
时间:2022-04-07 23:36
Semi-join *
不过并不是所有子查询都是半联接,必须满足以下条件:
子查询必须是出现在顶层的 WHERE、ON 子句后面的 IN 或者 =ANY子查询必须是单个 select,不能是 union;子查询不能有 group by 或者 having 子句(可以用 semijoin materialization 策略,其他不可以 );It must not be implicitly grouped (it must contain no aggregate functions). (不知道啥意思,保持原文);子查询不能有 order by with limit;父查询中不能有 STRAIGHT_JOIN 指定联接顺序;The number of outer and inner tables together must be less than the maximum number of tables permitted in a join.