多表联查,两表之间相互关联,不一定需要有主外键关系,字段匹配就行

Set @dlr = 15001;

SELECT school.name AS schoolName, xq.xqmc AS xqmc, qy.mc as qymc, ly.bz as lymc, fj.bz as fjmc FROM t_xsgy_ssap ssap

                LEFT JOIN t_xsgy_cwgl cwgl ON cwgl.id=ssap.cwid

                LEFT JOIN t_baseinfo_fj fj ON fj.id = cwgl.fj

                LEFT JOIN t_baseinfo_ly ly ON fj.lyid = ly.id

                LEFT JOIN t_baseinfo_qy qy ON ly.qyid = qy.id

                LEFT JOIN t_sys_school school ON ssap.ssxxid = school.id

                LEFT JOIN t_baseinfo_xq xq ON qy.ssxq = xq.id

        WHERE ssap.xhid = @dlr

                AND ssap.zszt =1

    原文作者:josnow
    原文地址: https://blog.csdn.net/josnow/article/details/72478605
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞