select name from [table name1] where id in(select id from [table name2])
select name from [table name1] where id in (select id from [table name2]) ??
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 其它条件
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 ....
??
楼主这样的写法当(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 其它条件
(
select * from table1 where id in (select id from table 2)
) b
where a.id = b.id and a.name = b.name ....