开发者

Is it possible to get count(*) and * more efficiently?

I'm now running two queries,which is not so efficient I think:

select count(*) from table where i开发者_高级运维d>0;
select * from table where id>0 limit 10;


You can do it using SQL_CALC_FOUND_ROWS.

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

But check out this blog entry about the performance of SQL_CALC_FOUND_ROWS.


If you are using PHP just run mysql_num_rows on the query.

$query = mysql_query("SELECT * FROM ... WHERE ...");
$rows = mysql_num_rows($query);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜