与内连接相交

时间:2014-04-21 22:46:22

标签: mysql sql

请如何使用内部联接转换此查询?

(SELECT DISTINCT tables.table_id AS 'Available table ID'
   FROM tables, reservation 
  WHERE tables.table_id = reservation.table_id 
    AND ((start_time <> ? AND date = ?)
          OR (date <> ?)) 
          OR status = 1)
INTERSECT
(SELECT DISTINCT tables.table_id AS 'Available table ID'
   FROM tables, reservation 
  WHERE tables.table_id = reservation.table_id 
    AND ((start_time <> ? AND date = ?) 
          OR (date <> ? AND reservation.table_id <> ?))
          OR status=1)

1 个答案:

答案 0 :(得分:-1)

你可以试试这个:(我不确定你是否在寻找这个答案)

(SELECT DISTINCT tables.table_id AS 'Available table ID'
   FROM tables JOIN reservation 
   ON (tables.table_id = reservation.table_id) 
   WHERE start_time <> ? AND date = ?
         OR (date <> ?)) 
         OR status = 1
INTERSECT
(SELECT DISTINCT tables.table_id AS 'Available table ID'
   FROM tables JOIN reservation 
   ON (tables.table_id = reservation.table_id) 
   WHERE start_time <> ? AND date = ? 
        OR date <> ? AND reservation.table_id <> ?)
        OR status=1
相关问题