I have a tasks
table as such:
+-------+-------------------+---------------------+---------------------+
| rowid | title | start_task | due_date |
+-------+-------------------+---------------------+---------------------+
| 1 | Paint Apartment | 2018-03-01 07:00:00 | 2018-03-16 15:00:00 |
+-------+-------------------+---------------------+---------------------+
| 2 | Meeting with John | 2018-03-10 10:00:00 | 2018-03-10 12:30:00 |
+-------+-------------------+---------------------+---------------------+
| 3 | Buy Milk | 2018-03-04 20:00:00 | NULL |
+-------+-------------------+---------------------+---------------------+
| 4 | Renew Rail Card | NULL | 2018-03-07 09:00:00 |
+-------+-------------------+---------------------+---------------------+
And I want to select everything for the week 2018-03-05
to 2018-03-11
so it should print rows 1,2 & 4.
So my query should include the following:
- Everything that starts between 2018-03-05 and 2018-03-11
- Everything that is due between 2018-03-05 and 2018-03-11
- Everything that the period of start_task and due_date falls within 2018-03-05 and 2018-03-11
My current SQL that does 1 and 2 and prints rows 2 & 4:
SELECT * FROM `tasks` tasks where ((`start_task` >= '2018-03-05 00:00:00' and `start_task` <= '2018-03-11 23:59:59') OR (`due_date` >= '2018-03-05 00:00:00' and `due_date` <= '2018-03-11 23:59:59'))