Table name: sample
--Item--|---datefrom---|--dateto--
Item A |0001-01-01 |2099-01-01
Item B |2017-11-20 |2017-12-31
Item C |2017-11-27 |2017-12-12
Supposing we have the data above. How do I construct the query in such a way that I will get what is the current effective item given the date today.
Example. Since today is 2017-11-29 then I should get ITEM C.
I've tried this but I'm just wondering if there is a more effective query for this?
select * from sample where datefrom>= (select datefrom from sample where datefrom < '2017-11-29' order by datefrom desc limit 1 ) and dateto <= (select dateto from sample where dateto > '2017-11-29' order by dateto limit 1)
select * from sample where datefrom <= now() and dateto >=now() order by datefrom limit 1?-infinityandinfinityinstead of those "magic dates".