I have the following query which retrieve all those who have ordered a book_id n°10 and but never ordered the book with id n°1. http://sqlfiddle.com/#!9/1bb9e8/44
|user_id | book_id |
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 10|
| 2 | 9 |
| 3 | 5 |
| 3 | 10|
| 4 | 6 |
| 4 | 7 |
| 4 | 10|
| 8 | 8 |
select u.user_id,o.book_id
from users u
inner join c
on u.user_id = o.user_id
and o.book_id = 10
where u.user_id not in (
select 02.user_id
from orders o2
where o2.book_id = 1 );
The keyword "except" is not available on MariaDB 10.1 What are the others way can this be written in SQL aside using a CTE that would be efficient ?