Sorting a list by the current time and the next dated records

0

I have the following table containing the programming of the day of the week "Sunday" of a radio:

(id, program, description, time_ini, end_time, link)

I want to get the first 3 programs using the current time as a reference.

    
asked by anonymous 01.05.2017 / 00:41

1 answer

2

Evaluate if the following code will serve you.

-- código #1
SELECT id, programa, descricao, hora_ini, hora_fim, link
  from tbProgramacao
  where id >= (SELECT id
                 from tbProgramacao
                 where hora_ini <= curtime()
                 order by hora_ini desc
                 limit 1)
  order by hora_ini asc
  limit 3;

To get the schedule that is on the air, you can walk in the table in the reverse order (from last to first), comparing with the current time. Once the programming id is in progress, just get the 3

I have not programmed for MySQL for some time; please test the code carefully.

In the WHERE clause of the main SELECT (the external), instead of id you can use time_ini:

where hora_ini >= (SELECT hora_ini
    
01.05.2017 / 01:13