选择用于另一个表的pair



我有两个表:

<表类> ID1 ID2 tbody><<tr>11111112222222

我建议使用exists:

select t2.*
from table2 t2
where exists (select 1
from table1 t1
where t1.id1 = t2.id1 and t1.id2 = t2.id2
);

注意,如果table1有重复的行,join可以返回重复的行。Exists不能。

简单连接:

select t2.*
from table2 t2
join table1 t1
on t1.ID1 = t2.ID1
and t1.ID2 = t2.ID2

最新更新