Your first example would require returning a potentially massive data set from the database simply for a count so I wouldn't suggest that.
I've seen the second one mentioned when dealing with massive datasets as well. Usually in conjunction with a set of triggers that when an row is inserted automatically increment the count and when a row is removed automatically decrement the count. This would be best stored in a separate table that contained only count values in my opinion.
Your other option would be the COUNT() function. Although with out benchmarking it I don't know if it would be any faster or slower than your first proposal.
Reputation Points: 265
Solved Threads: 126
Practically a Master Poster
Offline 623 posts
since Jul 2008