My database structure is as follows:
I have scheduletimes which have a classtime. Each scheduletime has a tclass associated with it that has a duration. I would normally use a join of some sort to grab the duration, however, since I am using the overlaps comparison in postgres I am not sure if this is possible. The query would look something like this…
Select (scheduletimes.classtime, scheduletimes.classtime + interval
(select duration from tclasses where tclass.id = scheduletimes.tclass_id) minutes) OVERLAPS
(06:50:00, 07:20:00) from schedules where
day = 1 and
schedule_id = 14;
You can use a subquery, but in your example you are mixing the literal format with a value from a column, which won’t work. And generally it is better to
JOINrather than to use a subquery, so you might want something like this: