I have a table structure like:
Events (id, name, start, end, venue)
Venues (id, name)
Where Events.start and end are representing start and end datetimes for the event. Events.veuue is a foreign key to Venues. I want to select all available venues in a time range. What might the SQL look like. At the moment, I have difficulties figuring that out…
You’ll need a
NOT EXISTSto get rows fromEventsthat don’t overlap your time ranges. I think this should do the job:The above uses a single datetime
[searchdate]. If you need a start/end range of dates to check venues for, use aWHEREclause like:So, if either
[searchstartdate]or[searchenddate]overlaps the event, a row will match.