This is how my history table looks like
start_date | end_date | name
-----------------------+------------------------+----------
2016-11-05 02:26:00+00 | 2016-11-10 01:55:00+00 | premium
2016-10-01 00:40:00+00 | 2016-11-30 01:55:00+00 | free
Records are ordered by start_date in descending order. I want to get the first row and then check if its end_date is greater then now(), if yes then return true else false.
I have written the below query by looking at some tutorials and its working fine but i don't know if this is efficient or not and how to write an optimised query for my question above.
SELECT history.end_datetime FROM history,
(SELECT id, end_datetime from history ORDER BY start_datetime
DESC LIMIT 1) subhistory WHERE history.id = subhistory.id AND
subhistory.end_datetime > now();