It is good to wrap a sql query to execute a row count query

Given an arbitrary sql query:

select foo from bar

this sql query can be very complicated, then I want to find out the record size of this query, so I just end it like this:

select count(*) from (select foo from bar)  t

Should I do it like this? Should I rely on some sort of indexed column, other than just usingcount(*)

Edit:


Sorry, forget to mention this: Performance is my main concern .

+4
source share
2 answers

COUNT (*) is the fastest way to count strings, because it does nothing.

COUNT (col), , col , dbms null, . , , COUNT (*). , col , dbms . , COUNT (*).

, COUNT (*). COUNT (col), - COUNT (DISTINCT col), .

(BTW: COUNT (1), dbms "" 1 . , 1 , dbms . COUNT (*) ?)

+1

Specefic to SQL Server: COUNT - , NULL. , foo select, COUNT(COLUMN) else COUNT(*).

0

All Articles