Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 计算sql查询中涉及SELECT特定行+FROM+WHERE+和的行数_Mysql_Count - Fatal编程技术网

Mysql 计算sql查询中涉及SELECT特定行+FROM+WHERE+和的行数

Mysql 计算sql查询中涉及SELECT特定行+FROM+WHERE+和的行数,mysql,count,Mysql,Count,如何返回此查询而不是查询结果返回的行数: SELECT collections.name, collections.description, collections.collection_id, collections.name, collections.description, collections.date, users.name FROM users, collections WHERE collections.user_id = users.user_id AND ( collecti

如何返回此查询而不是查询结果返回的行数:

SELECT collections.name, collections.description, collections.collection_id, collections.name, collections.description, collections.date, users.name
FROM users, collections
WHERE collections.user_id = users.user_id
AND (
collections.description LIKE  "%%searchTerm%%"
OR collections.name LIKE  "%%searchTerm%%"
OR users.name LIKE  "%%searchTerm%%"
)
AND (
reported = false
OR (
reviewed = true
AND approved = true
)
)
有两种方法,你可以

SELECT count(*)
FROM...

它将以实际数据为代价返回计数,或者您可以使用任何语言的函数查询数据库以检查有多少行。

您可以使用count1或countcollections.collection\u id

SELECT 
    count(collections.collection_id)
FROM 
    users,
    collections
WHERE 
    collections.user_id = users.user_id
    AND (
            collections.description LIKE  "%%searchTerm%%"
            OR collections.name LIKE  "%%searchTerm%%"
            OR users.name LIKE  "%%searchTerm%%"
        )
    AND (
        reported = false
        OR (
            reviewed = true
            AND approved = true
        )
    )

另请参见查找的\u行以及SQL\u计算\u查找的\u行

它的性能可能比使用COUNT*执行一个查询和另一个查询来获取数据要好


ie可以运行一个查询来获得结果,同时获得一个计数。好的,您仍然使用两个查询,但是第二个查询很便宜,它只是获取计算出的总数

SELECT DISTINCT COUNT*…在本例中,使用mysql请求PHP的语言进行倒计时可能是一个好主意。我应该重新考虑我正在做的事情,因为我确实会有限制地再次执行查询。此初始查询用于计算分页脚本中的页数。