Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 右连接和where条件_Php_Mysql - Fatal编程技术网

Php 右连接和where条件

Php 右连接和where条件,php,mysql,Php,Mysql,我只想显示可用的时间,以实现我正在尝试执行此查询 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'; 但是,如果我从medico_id和evento_inicio中删除where条件,它将检索0行,它将显示所有行,我如何进行查

我只想显示可用的时间,以实现我正在尝试执行此查询

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';
但是,如果我从medico_id和evento_inicio中删除where条件,它将检索0行,它将显示所有行,我如何进行查询以显示可用时间

p.D.议程表是空的,因为这是一个ajax呼叫和预约

从议程右键加入议程上的tbl\U hora.hora\U id=tbl\U hora.id\U hora

这意味着仅从议程表中选择其hora_id列在tbl_hora中具有匹配项的行以及tbl_hora表中的所有行

其中agenda.hora_id为null

并在仅加入其议程的行后从结果中选择。hora_id为null

这意味着您将始终获得0个结果,除非议程中有一行的.hora_id列为null,并且tbl____)中有一行的.id列也为null


您需要删除where agenda.hora_id为null并使用您搜索的条件

如果我删除agenda.hora_id为null条件,则我的结果将为0,因为我的议程表为空。如何才能更好地选择不在两个表中的结果。@Paul您能提供一个来自议程表和tbl_hora表数据的示例吗。因为你所说的,因为我的议程表是空的,这意味着议程在左侧,而右连接将永远不会带来结果!我用这个查询来解决这个问题,你怎么看?从不存在的tbl_hora中选择*从议程中选择hora_id,其中agenda.hora_id=tbl_hora.id_hor和medico_id=40,evento_inicio='2012-01-07';