如何检查限制是否在mysql中使用? [英] How to check if limit was used in mysql?

查看:53
本文介绍了如何检查限制是否在mysql中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在mysql查询中,我有类似选择和排序的命令,并使用where子句等.最后,例如,我有limit 10.像这样:

In mysql query, I have something like I select and order, and use where clause, etc..., and finally I have limit 10 for example. Something like this:

Select *
From employee
where fired=0
limit 10

问题是,我怎么知道是否使用了限制并且结果被截断了?基本上,我想轻松地知道是否有更多的结果从limit中删除.我不想做

The problem is, how do I know if limit was used and the result was truncated? Basically I want to know easily if there were more results that got cut off from limit. I don't want to do something like

Select (count *)
From employee
where fired=0

减去

Select (count *)
From employee
where fired=0
limit 10

有一种简单的方法吗?也许,就像您知道运行插入语句后如何使用内置函数get_sql_id()那样的php获取ID(类似)一样,是否有sql_count_without_limit()?

Is there a simple way for this? Perhaps, like you know how after you run an insert statement, you can get the id using php built in function get_sql_id() (something like that), is there a sql_count_without_limit()?

谢谢

推荐答案

您可以使用found_rows函数,如下所示:

You can use the found_rows function like this:

mysql> SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name
-> WHERE id > 100 LIMIT 10;
mysql> SELECT FOUND_ROWS();

有关更多信息,请参见 mysql参考

For more information see mysql reference

这篇关于如何检查限制是否在mysql中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆