select name from [table name1] where id=(select id from [table name2])
括号里的子查询的结果出来是一个结果集,有多个结果,但是我还想从这个结果集中继续查询其相对应的其他字段,请教该如何写SQL语句?谢谢大家

解决方案 »

  1.   

    select name from [table name1] where id in(select id from [table name2])
      

  2.   

    select name from [table name1] where id in (select id from [table name2])
    ??
      

  3.   

    1.
    楼主这样的写法当(select id from [table name2])这个子查询返回多个id时会导致错误,应该这样写(把"="换成"in"):
    select name from [table name1] where id IN (select id from [table name2])
    或者
    select a.name from [table name1] as a,[table name2] as b where a.id = b.id
    2.我还想从这个结果集中继续查询其相对应的其他字段:
    select a.name from [table name1] as a,[table name2] as b where a.id = b.id
     AND 其它条件
      

  4.   

    select * from table1 a,
    (
    select * from table1 where id in (select id from table 2) 
    ) b
    where a.id = b.id and a.name = b.name ....