比如: 人员表中,有两个分类字段(人员分类,二级分类),都要去关联 分类表,这时候应该怎么关联
我只知道一种解决方案,就起起别名,关联两遍,还有其他解决方案吗?
select t.name, c1.className,c2.className
left join userClass c1 on t.classid = c1.id
left join userClass c2 on t.class2id = c2.id
创建一个视图view,把两个表你要的字段都放进去。那样你就可以得到你要的关联。
楼主自己的方案就是最佳的解决方案了啊
select t.name, c1.className
left join userClass c1 on t.classid = c1.id
and t.class2id = c1.id
你的语句不全,贴出来这句过不了分析吧, t在哪?
select t.name, c1.className,c2.className
left join userClass c1 on t.classid = c1.id and t.class2id = c1.id