Mysql Left Join with Group By and Between

Viewed 78

I am having trouble to create a select query that will retrieve all users id that isn't in the games and availability between dates.

Example: Retrieve all users that are not between dates 2017-08-10 and 2017-08-12.

Get [3 , 4, 5]

Users

| Id | Name     |
| 1  | Jonh     |
| 2  | Mark     |
| 3  | Caroline |
| 4  | David    |
| 5  | George   |

Games

| Id | User_Id  | Start_Date | End_Date   |
| 1  | 1        | 2017-06-01 | 2017-06-01 |
| 2  | 1        | 2017-08-12 | 2017-08-13 |
| 3  | 4        | 2017-08-13 | 2017-08-14 |

Availability

| Id | User_Id | Start_Date | End_Date   |
| 1  | 1       | 2017-05-01 | 2017-05-25 |
| 1  | 2       | 2017-08-10 | 2017-08-17 |
| 1  | 3       | 2017-06-20 | 2017-07-10 |

I am using Laravel 5.4 but I'll glad if the answer is on Raw or Eloquent.

2 Answers
Related