select r.TableReservationId, d.TableId, d.TableName, d.StoreId
from dining_table d
LEFT join dining_table_reservation r on d.TableId=r.TableId
where r.Status=0
and r.StartTime not BETWEEN '2015-10-15 17:40:18' AND '2015-10-15 17:40:18'
这个只显示匹配记录,但我想要来自dining_table的所有记录,如果记录与条件匹配,则应跳过此记录
答案 0 :(得分:0)
select r.TableReservationId, d.TableId, d.TableName, d.StoreId
from dining_table d
LEFT join dining_table_reservation r on d.TableId=r.TableId
AND r.Status=0
and r.StartTime not BETWEEN '2015-10-15 17:40:18' AND '2015-10-15 17:40:18'
当LEFT JOIN
时,如果将这些右侧表条件放在WHERE
子句中,它将作为常规内连接执行。转而使用ON
子句!
答案 1 :(得分:0)
所以你想要所有的记录,表格中没有共同的值使用NOT IN
和你当前的结果
SELECT * FROM dining_table where TableId NOT IN
(select r.TableReservationId, d.TableId, d.TableName, d.StoreId
from dining_table d
LEFT join dining_table_reservation r on d.TableId=r.TableId
where r.Status=0
and r.StartTime not BETWEEN '2015-10-15 17:40:18' AND '2015-10-15 17:40:18');