mysql - How can I adjust a JOIN clause so that rows that have columns with NULL values are returned in the result? -


how can adjust join clause rows null value countlocid or countnatid columns returned in result?

in other words, if there no match in local_ads table, still want user's result nat_ads table returned -- , vice-versa.

select u.franchise, countlocid, totalprice, countnatid, totalnmoney, ( totalprice + totalnmoney )totalrev users u left join local_rev lr on u.user_id = lr.user_id left join (  select lrr_id, count( lad_id ) countlocid, sum( price ) totalprice local_ads group lrr_id )la on lr.lrr_id = la.lrr_id left join nat_rev nr on u.user_id = nr.user_id inner join (  select nrr_id, count( nad_id ) countnatid, sum( tmoney ) totalnmoney nat_ads month =  'april' group nrr_id )na on nr.nrr_id = na.nrr_id lr.month =  'april' , franchise !=  'corporate' order franchise 

thanks in advance help!

try following in clause while making left join. take rows right table matched condition

eg.

left join local_rev lr on (u.user_id = lr.user_id) or (u.user_id null) 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -