I am trying to return all rows from my 'Register' table that satisfy all date ranges specified by the rows in a closure table. The following query returns register entries for the corresponding first row of the closure table:
select * from Register where NOT(start_time > (select EndDate from Closures) OR start_time < (select StartDate from Closures)) group by id;
The closure table has the following start and end dates:
"2018-09-21" "2018-09-27"
"2018-06-12" "2018-06-12"
"2018-06-10" "2018-06-12"
"2018-06-15" "2018-06-15"
"2018-06-19" "2018-06-24"
but the query above only returns rows from Register as if the subquery returned 2018-09-21 and 2018-09-27, how do I get it to essentially run the outer query for all rows of the subquery?
May be you want to inner join register
like that?
SELECT r.*
FROM register r
INNER JOIN closures c
ON c.enddate >= r.start_time
and c.startdate <= r.start_time;