如何把sql查询出来的结果当做另一个sql的条件查询

2024-12-25 00:48:26
推荐回答(2个)
回答(1):

-- table2 的 name 作为 table1的条件
select * from table1 where name in (select name from table2)

--如果有多条语句,可以使用字段相加再等于
select * from table1 where fld1+fld2 in (select fld1+fld2 from table2)

--也可以使用INNER JOIN 进行查询
select a.* from table1 a inner join (select name from table2 group by name) b on a.name=b.name

回答(2):

嵌套查询就可以实现了,比如:

select * from (select col from table) t where t.col='1';