Getting the number of rows with a GROUP BY query

后端 未结 5 1157

I have a query to the effect of

SELECT t3.id, a,bunch,of,other,stuff FROM t1, t2, t3 
WHERE (associate t1,t2, and t3 with each other) 
GROUP BY t3.id 
LIMIT          


        
5条回答
  •  执笔经年
    2020-12-12 16:31

    All ans given will execute the query and then find the count. Distinct is definitely slower than group by on large dataset.

    Best way to find the count of group by is below

    SELECT 
        sum(1) as counttotal
    FROM (
        Your query with group by operator
    ) as T
    

    This will find the count while calculating group by.

提交回复
热议问题