Reputation: 349
There are 2 tables:
TableA
a b r1
c d r4
e f r6
TableB
r1 g1
r2 g1
r3 g1
r4 g2
r5 g2
How can I get next:
a b r1
a b r2
a b r3
c d r4
c d r5
For each r[i] from TableA find it in TableB and for each r[j] from TableB that have the same g[k] (same group) duplicate data from TableA.
Upvotes: 1
Views: 31
Reputation: 1270443
You can join to b
twice:
select a.*, bg.col1
from a join
b
on a.col3 = b.col1 join
b bg
on b.col3 = bg.col3;
Upvotes: 1