Can you count columns from a variation of the following query ?
set statistics time on
SELECT
OBJECT_SCHEMA_NAME(object_id) as dbo
,OBJECT_NAME(object_id) as rows
,SUM(Rows) AS NumOfRows --sum the rows if there are multiple partitions
FROM
sys.partitions
WHERE
index_id < 2 --ignore the partitions from non-clustered indexes if any
and OBJECT_NAME(object_id) = 'table'
GROUP BY
OBJECT_ID
ORDER BY
NumOfRows DESC
If not, is the next query the fastest way?
set statistics time on
SELECT COUNT(1) cnt, company FROM table
group by company
order by cnt desc
Thanks