简体   繁体   中英

Right join and where condition Mysql

I want to display only the time available, to achieve that I'm trying to do this query

select * from agenda  right join tbl_hora on agenda.hora_id = tbl_hora.id_hor where  agenda.hora_id is null and  medico_id = 40 and evento_inicio = '2012-05-05';

However, it retrieves me 0 rows if I remove the where conditions from medico_id and evento_inicio, it display all the rows, how could I make the query to display the available time.

PD the agenda table is empty, because is an ajax call to make and appointment.

from agenda right join tbl_hora on agenda.hora_id = tbl_hora.id_hora

this means select from agenda table only the rows that it's hora_id column has a match in the tbl_hora and all rows from tbl_hora table

where agenda.hora_id is null

and select from the result after joining only the rows that it's agenda.hora_id is null.

which means you will always get 0 results unless there is a row in agenda that it's .hora_id column is null and also a row in tbl_hora that it's .id column is null too

you need to remove the where agenda.hora_id is null and use the condition you search for instead

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM