mysql - Decide to do LEFT JOIN on which table based on CONDITION -


i have 2 tables. want left join 1 of tables based on condition. want this:

if (projects.paymenttype==1)     left join projectbudgetfixedprice on (projects.budget=projectbudgetfixedprice.id) else     left join projectbudgetperhourprice on (projects.budget=projectbudgetperhourprice.id) 

i have created following, not working.

select * projects left join (if (projects.paymenttype==1,projectbudgetfixedprice,projectbudgetperhourprice))     on  (if (projects.paymenttype==1,projects.budget=projectbudgetfixedprice.id,projects.budget=projectbudgetfixedprice.id))  (projects.statuscode=3 or projects.statuscode=4) , projects.suspended='n' , (projects.paymenttype=1 or projects.paymenttype=2) 

any or suggestions please?

you should able use union.

something like

select   *   projects   left join     projectbudgetfixedprice     on projects.budget = projectbudgetfixedprice.id   projects.paymenttype = 1   , ((projects.statuscode = 3 or projects.statuscode = 4)   , projects.suspended = 'n'   , (projects.paymenttype = 1 or projects.paymenttype = 2)) union select   *   projects   left join     projectbudgetperhourprice     on projects.budget = projectbudgetperhourprice.id   projects.paymenttype <> 1   , ((projects.statuscode = 3 or projects.statuscode = 4)   , projects.suspended = 'n'   , (projects.paymenttype = 1 or projects.paymenttype = 2)); 

hth


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -