I need to select items with defined idBook from exemplar table which are currently not ordered(booked)- dateReturn field in "orders" table is not null.
Table orders can contain previously fulfilled orders with the same idExemplar!
If exemplar has at least one record in "orders" table with dateReturned=null then this exemplar should be excluded!
I’ve tried to use this query:
select *
from exemplar
join orders on orders.idExemplar=exemplar.idExemplar
where dateReturned is not null
but it gives wrong result if table orders contains previusly fulfilled orders with the same idExemplar
Similar to @vizier’s answer, but expressed differently:
1) Using
NOT IN:2) Using
LEFT JOIN+WHERE IS NULL: