Hello,
I would like to ask for your help on solving a specific query.
Below here is a sample of records for a certain table that stores the ‘
start’ and ‘
end’ dates of a vacation leave of an employee.
Let's say I need to produce a report that will display the time record of an employee for a certain date range. I will specify a certain 'start' and 'end' date in order for that to achieve. But before I do that, I need to check records in this "leave" table so that I can display in the report that on a specific day, that employee is "on vacation leave".
this is the records in the 'leave' table:
Code:
Start Date End Date
2010-10-4 2010-10-9
2010-9-26 2010-10-2
2010-10-30 2010-11-4
2010-10-25 2010-10-25
If I specify:
Code:
Start date: 2010-10-1
End date: 2010-10-31
and would use this as query for retrieving records in the 'leave' table using this statement:
Code:
SELECT start_date, end_date FROM leave
WHERE start_date >= '2010-10-1' AND end_date <='2010-10-31';
But then it would only return records that starts from 2010-10-1 and ends in 2010-10-31,
Code:
Start Date End Date
2010-10-4 2010-10-9
2010-10-25 2010-10-25
but
I wanted also to get the records that are in the range of that start and end dates like for example the record
Code:
Start Date End Date
2010-9-26 2010-10-2
is valid for me because the date 2010-10-1 and 2010-10-2 is needed to provide information for my report which covers the date range of 2010-10-1 up to 2010-10-31.
How can I do that? Can anyone give me hints or clues? As I myself would also tinker on this problem and would post my answer if I happen to get it right.
Cheers!