Im trying to write query where im using valid_from and valid_to but those values can be null or one of them.
select * from omr_approval_teams where now() between valid_from and valid_to ;
This is my query, so i want to return data using if both valid_from and valid_to is null, or both not null or only valid_to is null. Any suggestion how can i achive that?
Advertisement
Answer
You could just explicitly add passes for null date bounds:
SELECT *
FROM omr_approval_teams
WHERE (NOW() >= valid_from OR valid_from IS NULL) AND
(NOW() <= valid_to OR valid_to IS NULL);