如何获取本应返回的行数?

发布于 2024-09-09 15:48:32 字数 219 浏览 0 评论 0原文

在以下查询中:

SELECT column1,column2 FROM table1 ORDER BY column1 LIMIT 0,30

如何找出如果没有 LIMIT 将返回的行数?

编辑:我正在寻找一种方法将其处理到上面的查询中,而不是进行单独的查询。 (如果可能的话。)

In the following query:

SELECT column1,column2 FROM table1 ORDER BY column1 LIMIT 0,30

How can I find out the number of rows that would have been returned were it not for the LIMIT?

Edit: I am looking for a way to work this into the query above and not do a separate query. (If possible.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北凤男飞 2024-09-16 15:48:32
SELECT COUNT(*) FROM table1;
SELECT COUNT(*) FROM table1;
━╋う一瞬間旳綻放 2024-09-16 15:48:32

如果您执行此查询:

 SELECT SQL_CALC_FOUND_ROWS column1,column2 FROM table1 ORDER BY column1 LIMIT 0,30;

您可以检索上一个 SELECT 找到的行数

select FOUND_ROWS();

如果您确实必须使用一个查询来执行此操作,则必须使用子选择(这将具有添加额外列的缺点每行..)

 SELECT column1,column2,s.total FROM table1,
    (select count(*) as total from table1) s 
 ORDER BY column1 LIMIT 0,30;

If you do this query:

 SELECT SQL_CALC_FOUND_ROWS column1,column2 FROM table1 ORDER BY column1 LIMIT 0,30;

You can retrieve the number of rows the previous SELECT found with

select FOUND_ROWS();

If you really must do it with one query, you'll have to use a sub select (which'll have the disatvantage of adding an extra column to every row..)

 SELECT column1,column2,s.total FROM table1,
    (select count(*) as total from table1) s 
 ORDER BY column1 LIMIT 0,30;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文