On 14 December 2010 21:53, Ron Piggott <ron.piggott@xxxxxxxxxxxxxxxxxx> wrote: > > What change is needed to this query so if âcurrently_in_rssâ is NULL it will be assigned a value of 0 > > SELECT `reference`, COUNT(`reference`) AS currently_in_rss FROM `ministry_profiles` WHERE `rss_feed_include` = 1 GROUP BY `rss_feed_include` > > Ron Doesn't that query give you an error saying that `reference` isn't in the GROUP BY clause? I use MS SQL, so the wording my be different but it would be along the lines of ... For the SQL statement : SELECT POH_Contract, COUNT(POH_Contract) FROM [BV-CLUSTER-SQL].Contracts.dbo.POP_Header WHERE POH_Status = 1 GROUP BY POH_Status Column 'bv-cluster-sql.contracts.dbo.pop_header.POH_CONTRACT' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. So, fixing the query ... SELECT POH_Contract, COUNT(POH_Contract) FROM [BV-CLUSTER-SQL].Contracts.dbo.POP_Header WHERE POH_Status = 1 GROUP BY POH_Status, POH_Contract now works. So, your query may need to be SELECT `reference`, COUNT(`reference`) AS currently_in_rss FROM `ministry_profiles` WHERE `rss_feed_include` = 1 GROUP BY `rss_feed_include`, `reference` Normally COUNT() will count NULLs, but as you are grouping by the counted column, nulls would be in their own row. Richard. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php