SQL Filter (Result that should not appear)

1

is the following I'm creating an online schedule and I need to list them and show the schedules that are not scheduled, to show the free time. And for this I created the scheduling_table, where in the column schedules_fixes the list of schedules, and in the other table the scheduling is where the schedules are and I need the value that is in the scheduling_table in the case in the column schedules_fixes, only the schedules that do not appear have been scheduled, and the problem that is happening that is appearing example:

I need the values of a table with fixed times not to appear in the select.

The fixed times are: 02:00 02:10 02:20 02:30

Then a person scheduled the time from 02:00 to 02:30, so the times of 02:10, 02:20 are appearing in the select and should not.

follows the query I made:

SELECT horariosfixos 
FROM agendamento_horarios 
WHERE horariosfixos NOT IN(SELECT horaInicio 
                           FROM agendamento 
                           WHERE data = '17-10-2016' 
                           UNION 
                           SELECT horaFim 
                           FROM agendamento 
                           WHERE data = '17-10-2016')

If you can help me, I'm grateful.

    
asked by anonymous 18.10.2016 / 16:10

2 answers

0

I believe this SELECT can help you solve:

SELECT Ah.horariosfixos 
FROM agendamento_horarios Ah
LEFT OUTER JOIN agendamento Ag
  ON Ag.horaInicio <= Ah.horariosfixos 
  AND Ah.horariosfixos < Ag.horaFim
  AND Ag.data = '17-10-2016'
WHERE Ag.horaInicio IS NULL
    
18.10.2016 / 19:02
-1

Rick thanks for the help, after you sent me the code you did, gave me a light, and then I put the code up and it worked, it goes on:

  

SELECT Ah.hourshots   FROM scheduling_hours Ah, scheduling Ag where ag.hosting < > ah.hourshots & ag.hosting < = ah.hourshots

    
19.10.2016 / 02:48