(1)
比如:
select U.*, G.* from user U left join group G on U.gid = G.id and U.sid = G.sid红字部分怎么解决啊?为什么起不到两个一起限制的作用呢?如何能联表on后面两个限制条件呢?
(2)
查询N个表,如何做到,表A联接完表B,然后再表A联接表C呢?
(3)
select A.*, B.*, C.* from a A left join b B left join c C
那么其中的最后面的left join c C是a和c链的还是b和c链的?

解决方案 »

  1.   

    (1)
    比如:
    select U.*, G.* from user U left join group G on U.gid = G.id and U.sid = G.sid红字部分怎么解决啊?为什么起不到两个一起限制的作用呢?如何能联表on后面两个限制条件呢?应该可以,贴记录出来看看
    (2)
    查询N个表,如何做到,表A联接完表B,然后再表A联接表C呢?
    select * from (a left join b on ..) left join c on ...
    数据库要自动优化(3)
    select A.*, B.*, C.* from a A left join b B left join c C
    那么其中的最后面的left join c C是a和c链的还是b和c链的?
    与ON有关,ON A.F1=C.F1 是和a链
    ON B.F1=C.F1 是和C链
      

  2.   


    高手的意思是不是这个语句是A和B连,然后B和C连啊
      

  3.   

    1 and后面起作用
    2 select * from a left join b on a.col1=b.col1 left join c on a.col2=c.col2
    3 select * from a left join b on a.col1=b.col1 left join c on a.col2=c.col2
      

  4.   

    select t1.gid as t1gid, t2.gid as t2gid, t3.gid as t3gid from t1 left join t2 on t1.gid = t2.gid left join t3 on t3.gid = t1.gidselect t1.gid as t1gid, t2.gid as t2gid, t3.gid as t3gid from t1 left join t2 on t1.gid = t2.gid left join t3 on t3.gid = t2.gid
    刚试了一下,的确如1楼所说的要看on了