I have a table that looks as follows service:
id | service | status | multicall | date_created |
--------------------------------------------------------------------
10 | Cleaning | 1 | 0 | 2016-09-20 19:11:01 |
11 | Gardening | 1 | 0 | 2016-09-20 19:12:07 |
12 | Dishes | 1 | 1 | 2016-09-20 19:14:28 |
13 | Take out rubbish | 1 | 1 | 2016-09-20 19:14:28 |
This a a table that users can can select service from that they want someone to do.
Once the service is finished, the user history gets saved in a different table user_service_hist:
id | user_id | service_id | date_created |
--------------------------------------------------
1 | 1 | 10 | 2016-11-25 10:49:05
2 | 1 | 11 | 2016-11-27 23:58:46
3 | 1 | 12 | 2016-11-28 00:01:36
4 | 1 | 13 | 2016-11-28 12:07:17
The user can only select each service once EXCEPT the service marked with a multicall column value of 1.
When I call the list of available service I use the follwing query:
SELECT s.id, s.service, s.date
from service s WHERE not exists (Select 1 from user_service_hist ush
where ush.service_id = s.id AND ush.user_id = 1)
This query selects zero rows as I the user has completed all services. I would like to display service nr. 12 and 13 always as these have a multicall column value of 1, regardless of whether it was completed or not. Could someone tell me how to modify my query?