How to select records in a table using as reference the datetime present?

Asked

Viewed 24 times

0

This select returns me the oldest records to the future. But I wanted to exclude from the results the events that have already passed and first display the current event.

SELECT id, programa, descricao,data_hora 
   from wp_programacao
   where id >= (SELECT programa
                 from  wp_programacao
                 where data_hora <= now()
                 order by data_hora desc
                 limit 1)
  order by data_hora asc
  limit 5;
  • try to change where data_hora <= now() for where data_hora < now()

  • and why leave it as a quote, you didn’t write?

  • Yes... I’ll take it back

  • @Lucascosta keeps returning me the oldest record.

1 answer

1


select id, programa, descricao, data_hora 
from wp_programacao
where data_hora >= now() 
order by data_hora asc
limit 5;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.