Nick
Nick

Reputation: 575

mysql Left join, mysql does an inner join?

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!

Upvotes: 1

Views: 194

Answers (1)

zerkms
zerkms

Reputation: 254886

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

Upvotes: 4

Related Questions