即使连接表是空的,也显示行?

时间:2013-01-21 18:05:15

标签: mysql

如果我从另一个表中检索一个场地列表及其关闭时间,如下所示:

$fullDate = date('Y-m-d H:i:s');

$query="SELECT
venues.ID,
venues.VENUE_NAME,
locations.LOCATION,
hrs.opening_day,
hrs.opening_time,
hrs.closing_time
FROM venues
INNER JOIN venue_types
ON venues.VENUE_TYPE = venue_types.ID
INNER JOIN locations
ON venues.VENUE_LOCATION = locations.ID
INNER JOIN hours_of_operation hrs
  on hrs.venue_id = venues.id
     and ((hrs.opening_day=date_format('$fullDate' - INTERVAL (closing_time<opening_time and time('$fullDate')<closing_time) DAY, '%a')))
GROUP BY venues.VENUE_NAME";

我得到的结果是我已经在hours_of_operation指定了特定日期的开始/结束时间。如果当天的hours_of_operation行是否为空,我将如何显示所有场地?

谢谢! :)

1 个答案:

答案 0 :(得分:4)

使用LEFT JOIN:

...
LEFT JOIN hours_of_operation hrs
...