Reputation: 89
I have 2 tables in Oracle DB and one table contains Column A, B and other table contains columns A, B, C. first two columns are same in both the tables, However, columns A, B in both tables have different data so A -> B relationship both tables is different.
So I want to run a query to fetch data which contains Table1 A, Table1 B, Table2C where Table1 B= Table2 B;
Select Tab1.A, Tab1.B, (select Tab2.C from Tab2 where Tab1.B=Tab2.B )
FROM Tab1 WHERE Tab1.A IN (1,2,3,4,5);
Upvotes: 0
Views: 749
Reputation: 1269693
Your query is likely to return an error because there are probably multiple rows in the second table with the same B
value. Why not just use JOIN
?
SELECT Tab1.A, Tab1.B, Tab2.C
FROM Tab1 JOIN
Tab2
ON Tab1.B = Tab2.B
WHERE Tab1.A IN (1, 2, 3, 4, 5);
Upvotes: 2