我有两个表:
<表类>
ID1
ID2
tbody><<tr>111 1111 222 2222 表类>
我建议使用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