Conditional inner join statements in MySQL

纵然是瞬间 提交于 2019-12-04 16:39:28

Left / outer join to each of the three options and the conditional in your select will take care of the rest.

Perhaps something like:

...
LEFT JOIN smdealershipjoins smdj 
    ON j.dealershipID = smdj.dealership
LEFT JOIN smgroupjoins gj 
    ON j.dealershipID = gj.groupID
LEFT JOIN smagencyjoins aj 
    ON j.dealershipID = aj.agencyID
LEFT JOIN userinfo ui 
    ON ui.userID = CASE
        WHEN j.idType = 'dealership' THEN smdj.sm
        WHEN j.idType = 'Group' THEN gj.sm
        WHEN j.idType = 'Agency' then aj.sm
    END
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!