我有4个表a,b,c,d
a
machineid
a1
b
routinid
b1
c
machineid
routinid
c1
d
machineid
routinid
d1如何实现如下效果select c1.*,d.d1,a.a1.b.b1 from c left join a on a.machineid=c.machineid 
left join b.routinid=c.routinid left join d on (c.routinid=d.routinid and d.machineid=c.machineid)
好像left join不支持on (c.routinid=d.routinid and d.machineid=c.machineid) 这种语句
如果想实现类似效果怎么做呢?

解决方案 »

  1.   

    select c1.*,d.d1,a.a1.b.b1 from c left join a on a.machineid=c.machineid 
    left join b.routinid=c.routinid left join d on (c.routinid=d.routinid and d.machineid=c.machineid) 
    好像left join不支持on (c.routinid=d.routinid and d.machineid=c.machineid)
    这里错了.改成
    left join b on b.routinid=c.routinid left join 
      

  2.   

    错了一大堆
    select c.*,d.d1,a.a1,b.b1 from c left join a on a.machineid=c.machineid 
    left join B ON b.routinid=c.routinid left join d on (c.routinid=d.routinid and d.machineid=c.machineid) 
      

  3.   

    我在access里用的。。当然 我加了() 在这懒得加了。。大概就是这么个意思。。
    我想到办法解决这个问题了,谁若能告诉我sql server支持 left join on ( a=b and c=d) 这种写法。我就把分给谁
      

  4.   

    老大,join 的时候你的条件只能是相关联的这2个表或查询所包含的字段,如果你要join a和b表,而条件中却加入他们之外的表的字段,肯定是不能的。