I want to do a left join but mysql just does an inner join? whats wrong with my query?
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 only gives those avHours who have a corresponding appointment
Thanks in advance!
Because of these conditions:
and ap.calendarid = 2
and ap.appointmentdate = "2012-10-01"
you only select rows from tbl_appointment
which are not null
.
If that's what you want - move them to the left join's ON
part
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.