表a 
id,userid,name,age,sex 
1      1    1     2    3 
2      1    4     5    6 
3      2    1     1    1  
表b 
id  userid,friendid, 
1      1      1 
2      1      1 
3      2      2
表c
id     uid  name
1       1    kk
2       2    dd
表d
id    uid    photo
1      1     jj
2      2     ccc
b.friendid=a.id c.uid=a.id  d.uid=a.id我想通过userid=1查询表b的全部属于userid=1的friendid,和friendid所对应的a表的name,age,sex c表的name d表photo我想实现的是: 
friendid  name age sex name  photo
1          1     2  3   kk    jj  
1          4     5  6   dd    ccc 急用,谢谢 

解决方案 »

  1.   

    c,d表里面的uid对应的b表中的id吗?否则看不出关系来。
      

  2.   

    select b.friendid friendid  a.name name, a.age age a.sex sex c.name name1 d.photo photo from a,b,c,d where b.friendid=1 and a.userid=b.userid and c.uid=a.userid and d.uid=a.userid order by friendid
      

  3.   

    Select 
    distinct 
    b.friendid ,a.name, a.age, a.sex, c.name,  d.photo  
    from 
     a 
    join 
     b on a.ID=b.friendid
    join
     c on c.uid=a.ID
    join
     d on d.uid=a.ID
      

  4.   

    Select 
    distinct 
    b.friendid ,a.name, a.age, a.sex, c.name,  d.photo  
    from 

    join 
    b on a.ID=b.friendid 
    join 
    c on c.uid=a.ID 
    join 
    d on d.uid=a.ID