I have a table and want to get records where now (current timestamp) between two timestamps (if not null):
id title start end
1 A 1450718820 1450719000
2 B null null
3 C 1450718820 null
4 D null 1450718000
Example 1: if current timestamp - 1450717990 I need records with ID: 2,4
Example 2: if current timestamp - 1450718830 I need records with ID: 1,2,3
Example 3: if current timestamp - 1450719010 I need records with ID: 2,3
Thanks! start and end are bigint(20) fields
You can use logic such as:
select t.*
from t
where (start is null or unix_timestamp() >= start) and
(end is null or unix_timestamp() <= end);