mysql - Using cases to determine which table should join -
i have 4 tables products, product_histories, vendor_invoices , invoices
this query have developed
select p.product_id, product_name, vendor_name products p inner join product_histories ph on p.product_id = ph.product_id case when ph.history_type = "p" left join vendor_invoices vi on link_id = vi.vi_id when ph.history_type = "s" left join invoices on i.invoice_id = link_id end order ph_id asc what want if ph.history_type p should join vendor_invoices , if s should join invoices. says there syntax error. can me out it? or show better way achieve problem.
Comments
Post a Comment