Reputation: 8717
I have the following query.
SELECT COUNT( * ) AS offer_count
FROM restaurants_offers
WHERE DATE( NOW( ) )
BETWEEN date_start
AND date_end
AND restaurant_id =1
Now, when count is greater than zero I want to select true
else false
, instead of count as the query result. How to do that?
Upvotes: 15
Views: 30233
Reputation: 31
SELECT COUNT( * ) > 0 AS has_offers
FROM restaurants_offers
WHERE DATE( NOW( ) )
BETWEEN date_start
AND date_end
AND restaurant_id =1
Upvotes: 3
Reputation: 263713
Try this:
SELECT IF(COUNT(*) > 0, 'true', 'false') AS NewResult
FROM restaurants_offers
WHERE (DATE(NOW()) BETWEEN date_start AND date_end) AND
restaurant_id = 1
Upvotes: 30
Reputation: 204756
SELECT case when COUNT(*) > 0
then 1
else 0
end AS offer_count
FROM restaurants_offers
WHERE DATE( NOW( ) )
BETWEEN date_start
AND date_end
AND restaurant_id =1
or if you need the words true
and false
SELECT case when COUNT(*) > 0
then 'true'
else 'false'
end AS offer_count
...
Upvotes: 1