select - MySQL Join three table if one table no record -


$numquery1 = " select d.*      , r.*      , avg(c.on_time)+avg(c.friendly)+avg(c.language_skills)+avg(c.professional) ranking   comment c   left    join driver d     on d.userid = c.driver_id   left    join driver_rental r     on r.email = d.email         (         $driver_rental not null     , $driver_rental != ''    , car_type_1 >= $_session[car_type_1]       )     or car_type_2>=$_session[car_type_1]); "; 

if comment table have no driver_id record, result null, can ignore comment table in select statement cannot without it?

$numquery1 = "select driver.*, driver_rental.*, avg(comment.on_time)+avg(comment.friendly)+avg(comment.language_skills)+avg(comment.professional) ranking     comment     left join driver     on     driver.userid = comment.driver_id     right join driver_rental     on     driver.email = driver_rental.email         ($driver_rental not null , $driver_rental != '') , (car_type_1>=$_session[car_type_1] or car_type_2>=$_session[car_type_1])"; 

the idea not stress on driver table in either join. instead of second left join use right join driver_rental


Comments