mysql左连接,mysql做内连接?

时间:2012-10-01 01:42:39

标签: mysql left-join

我想做一个左连接但是mysql只做一个内连接? 我的查询有什么问题?

select av.*, ap.* 
from tbl_available av 
left join tbl_appointment ap 
on av.avHours = ap.appointmenttime 
where av.avCalendarId = 2 
and (ap.calendarid = 2 or ap.calendarid= null)
and (ap.appointmentdate = "2012-10-01" or ap.appointmentdate = null)
and av.avDays = DayOfweek("2012-10-01")
order by avHours

mysql只给那些有相应约会的avhours

提前致谢!

1 个答案:

答案 0 :(得分:4)

由于这些条件:

and ap.calendarid = 2 
and ap.appointmentdate = "2012-10-01" 

您只选择tbl_appointment中不是null

的行

如果这就是你想要的 - 将它们移到左边连接的ON部分