I recently found that a query would not work on some of my records if the values where null. Apparently in SQL, null cannot be compared to anything – even null.
UPDATE company SET views = IF(views, views + 1, 1),
trendingViews = IF(viewed != '2012-05-21 00:00:00', 1, trendingViews + 1),
viewed = IF(viewed != '2012-05-21 00:00:00', '2012-05-21 00:00:00', viewed)
WHERE id = '3024'
How can I change this query to conditionally check for the values provided and null?
use COALESCE: