--userid1对应的username
SELECT username
FROM table1,table2
WHERE table1.userid=table1.userid1--userid2对应的类似

解决方案 »

  1.   

    select a.* from table2 a,table1 b where a.userid=b.userid and b.username=条件
      

  2.   

    select t1a.username, t1b.username 
    from table2 t2 inner join table1 t1a on t2.userid1 = t1a.userid
        inner join table1 t1b on t2.userid2 = t1b.userid
      

  3.   

    to xelite(潜龙):
    这样分别查我会。我想问得是一次可否查询得到?怎样做这个视图?
      

  4.   

    create view v_table2
     as
       select a.* from table2 a,table1 b where a.userid=b.userid and b.username=条件
    Go
      

  5.   

    select a.username,b.username
    From table2 c 
         join table1 a on c.userid1 = a.userid
         join table1 b on c.userid2 = b.userid
      

  6.   

    SELECT username
    FROM table1,table2
    WHERE table1.userid=table2.userid1 or table1.userid=table2.userid2 
      

  7.   

    select a1.username,a2.username
    from table2 b left join table1 a1 on b.userid1=a1.userid
    left join table1 a2 on b.userid2=a2.userid