我需要从 exemplar
表中选择当前未订购(已预订)的具有已定义 idBook 的项目 - “订单” 表中的 dateReturn 字段不为空。
表 orders
可以包含以前完成的具有相同 idExemplar 的订单!
如果范例在“订单”表中至少有一个 dateReturned=null 的记录,那么应该排除该范例!
我试过使用这个查询:
select *
from exemplar
join orders on orders.idExemplar=exemplar.idExemplar
where dateReturned is not null
但如果订单表包含具有相同 idExemplar 的先前已履行的订单,则会给出错误的结果
最佳答案
如果我正确理解了问题,这应该可以解决问题:
select *
from exemplar
where not exists
( select *
from orders
where orders.idExemplar=exemplar.idExemplar
and dateReturned is null )
关于mysql - 非标准sql查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10667692/