I have two big tables:
A: (ID1,VAR1);
B: (ID1,ID2,VAR2)
And a third table:
C: (ID2...)
I’d like to merge A and B only for the records having values from C.
Below is my thought by using “IN”. Is there a more efficient way to do this? Sometimes I found that “IN” does not work so well.
Thanks a lot!
select A.VAR1,B.VAR2
from A
INNER JOIN
(
select ID1,VAR2
from B
where ID2 in
(select distinct ID2
from C
)
) D
on A.ID1=D.ID1
There is no need to use the subqueries, you just need to do a
JOINon all of the tables: