问题描述:

Events have start_at and end_at fields

How do I check if there is any overlap between two events using only database queries?

In other words, is something like

(Event1.start_at BETWEEN Event2.start_at AND Event2.end_at) OR (Event1.end_at BETWEEN Event2.start_at AND Event2.end_at)

possible with .where function?

Thanks!

网友答案:

If you're using MySQL, it also has a BETWEEN ... AND (which is just a shortcut for (min <= expr AND expr <= max)).

相关阅读:
Top