sql嵌套查询,left join不上,帮忙看看语句写得有没问题
select b.classid, ……
from
(select a.id,…… left join Table2 c on a.id = c.id) b
查询出来的结果是
CLASSID
201001
201002
加了left join后
select b.classid, c.classname ……
from
(select a.id,…… left join Table2 c on a.id = c.id) b
left join classes c
on b.classid = c.classid
查出来是
CLASSID CLASSNAME
201001
201002
查出来结果classname是空的???(classes表里的classid字段有201001 201002 这两个记录)
------解决方案--------------------select b.classid, c.classname ……
from
(select a.id,…… left join Table2 c on a.id = c.id) b
left join classes c
on trim(b.classid) = trim(c.classid)