I have a table which stores in each row a meeting with start date/time and end date/time.
meetingID int
meetingStart datetime
meetingEnd datetime
Desired output: For each pair of overlapping rows I would like to output
meetingID, meetingStart, meetingID, meetingEnd
What’s the most efficient way to perform such a query in MySQL?
This will select each pair twice.
If you want each pair to be selected just once, use:
Make sure you have indexes on
meetingStartandmeetingEndfor the query to work efficiently.MySQL, however, will probably useINDEX MERGEto run this query, which is not very efficient in current implementation.You also may try to use:
, which is more complex but will most probably run a little bit faster.