我有个问题: SELECT SQL_CALC_FOUND_ROWS DISTINCT something.* FROM someting WHERE TRUE AND something.is_active=1 ORDER BY long_id DESC
. 上面的查询将检索一些对象和文档。
在检索文档/对象本身之前,是否可以从该查询中获取文档/对象的总数?
这里的情况是表“something”可以有超过100000个文档/对象,因此不能由php处理(返回致命错误内存不足)。因此,我想知道将从查询中检索多少文档/对象。
我试过 COUNT
:
SELECT COUNT(*) SQL_CALC_FOUND_ROWS DISTINCT something.* FROM something WHERE TRUE AND something.is_active=1 ORDER BY long_id DESC
SELECT COUNT(SQL_CALC_FOUND_ROWS DISTINCT something.*) FROM something WHERE TRUE AND something.is_active=1 ORDER BY long_id DESC
SELECT SQL_CALC_FOUND_ROWS DISTINCT COUNT(something.*) FROM something WHERE TRUE AND something.is_active=1 ORDER BY long_id DESC
但总有这样的错误: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ...
.
2条答案
按热度按时间nfs0ujit1#
既然你用了
COUNT
,无需使用SQL_CALC_FOUND_ROWS
. 另外,我删除TRUE
因为它是不必要的。roejwanj2#
只需简化查询并计算所有结果。
DISTINCT something.*
也没有意义(除非您的表没有主键,我对此表示怀疑)。