用另一个 table 中的多列子集 table

Subsetting a table by multiple columns in another table

从下面的 Table A 中,我想 select A2 = 1 和 A1 - A3 组合作为 B1 - B2 组合存在于 Table B 中的行以下。结果应该是 Table C。我该怎么做?我的实际表很大,所以效率很重要。谢谢你。

Table一个

A1   |A2  |A3  |A4
-----+----+----+----
a    |1   |9   |o   
b    |1   |10  |k
c    |0   |2   |d   
d    |0   |12  |f
e    |1   |8   |g   
f    |1   |14  |h
e    |1   |12  |p   

Table B

B1   |B2  |B3  
-----+----+----
a    |9   |k    
a    |9   |l  
c    |2   |m   
e    |8   |o  
c    |3   |p   
e    |8   |q  

Table C

A1   |A2  |A3  |A4
-----+----+----+----
a    |1   |9   |o   
e    |1   |8   |g   
select A1, A2, A3, A4
from   tableA
where  A2 = 1
and    exists (select 1
               from   tableB
               where  B1 = A1
               and    B2 = A3); 

取决于您的 table 模式:

select     A1, A2, A3, A4
from       tableA
inner join tablaB
on         A1 = B1
and        A3 = B2
where      A2 = 1;