0

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);
2
  • And what is wrong with your query? Also, sample data and desired results would help. Commented Feb 22, 2019 at 20:55
  • With my query third column result is showing up as null instead of picking the value from the second table. Commented Feb 22, 2019 at 20:56

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.