WHERE isApproved = false
SELECT T_COMMENTS.ISAPPROVED, COUNT(*) AS CNT, T_WEBLOG.ID, T_WEBLOG.B_PUBLISHED FROM T_WEBLOG INNER JOIN T_COMMENTS ON T_WEBLOG.ID = T_COMMENTS.C_BID_FK WHERE T_COMMENTS.ISAPPROVED='FALSE' GROUP BY T_WEBLOG.ID, T_COMMENTS.ISAPPROVED, T_WEBLOG.B_PUBLISHED HAVING (((T_WEBLOG.B_PUBLISHED)=TRUE))
SELECT T_WEBLOG.ID, COUNT(NULLIF( T_COMMENTS.ISAPPROVED, 'False' )) AS UNAPPROVEDCNT, COUNT(NULLIF( T_COMMENTS.ISAPPROVED, 'True' )) AS APPROVEDCNT
FROM T_WEBLOG INNER JOIN T_COMMENTS ON T_WEBLOG.ID = T_COMMENTS.C_BID_FK
WHERE(((T_WEBLOG.B_PUBLISHED)=TRUE))
GROUP BY T_WEBLOG.ID
Originally posted by ruiribthe most pertinant reason for using cont(1) is incase there are any null values in the column you are trying to count as it will not include them if there are, so just safer to use count(1) just incase
A bit off discussion, but I am always interested in performance related issues. I always use COUNT(*) because I thought the optimizer would choose the best possible way to compute the count. Turns out that is true for several other variations, including COUNT(1):
http://thehobt.blogspot.com/2008/12/debunking-myth-select-count-vs-select.html
This is obviously valid for SQL Server. Not sure how other DBs handle this situation.
Originally posted by ruiribcool, I'm obviously too used to older databases where (1) was more efficient than (*), better change my ways
COUNT(*) counts NULLs, Huw: http://msdn.microsoft.com/en-us/library/ms175997.aspx
That does make sense too, as * is not really an expression, so the end result of it's use is that the query result will simply be the row count.
A quick google search will show that using COUNT(*) or COUNT(1) is implemented the same way for other DBs too, like Oracle.