MySQL子查询不支持limit
时间: 2023-11-07 15:52:16 浏览: 111
MySQL子查询不支持使用LIMIT关键字。如果在子查询中使用LIMIT,会导致错误。\[1\]\[2\]然而,可以通过在有LIMIT关键字的子查询的外面再包一层来解决这个问题。\[2\]另外,还可以将限制条件放到FROM子句而非WHERE子句中,以避免嵌套查询。\[1\]在这种情况下,需要给FROM后的SELECT语句起一个别名,例如使用AS关键字。\[1\]以下是一些正确执行的示例查询语句:\[3\]
- SELECT id FROM admin LIMIT 2,50;
- SELECT * FROM (SELECT id FROM admin LIMIT 2,50) AS ad;
- SELECT ad.* FROM (SELECT id FROM admin LIMIT 2,50) AS ad;
- SELECT * FROM (SELECT id FROM admin LIMIT 2,50) ad;
- SELECT ad.id FROM (SELECT id FROM admin LIMIT 2,50) AS ad;
- SELECT id FROM (SELECT id FROM admin LIMIT 2,50) AS ad;
请注意,给FROM后的SELECT语句起别名是非常重要的,如果不这样做,系统仍然会报错。\[1\]
#### 引用[.reference_title]
- *1* [mysql子查询不支持limit问题解决](https://blog.csdn.net/wangcomputer2010/article/details/24002347)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [mysql子查询中不能使用LIMIT](https://blog.csdn.net/czh500/article/details/86275400)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文