Home » SQL & PL/SQL » SQL & PL/SQL » Conditional Join Logic (Oracle 11g)
Conditional Join Logic [message #661503] Tue, 21 March 2017 23:30 Go to next message
rajsinha
Messages: 4
Registered: February 2016
Junior Member
Hi,

I need to join 2 different tables on different columns in the same table. However, I need to fetch the records if either of the join condition is true..

Select
A.*
From A INNER JOIN TAB_A ON A.COLA = TAB_A.COLA
INNER JOIN TAB_B ON A.COLB = TAB_B.COLB

I want to simulate a logical OR condition between the joins and retrieve the record if either of the join conditions above is true.

Please advise.
Re: Conditional Join Logic [message #661504 is a reply to message #661503] Wed, 22 March 2017 01:37 Go to previous messageGo to next message
Michel Cadot
Messages: 65971
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Use OUTER JOINs.

And, if you want to continue to get help, feedback in your previous topics.
And follow OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Also always post your Oracle version, with 4 decimals, as solution depends on it.

With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.


Re: Conditional Join Logic [message #661507 is a reply to message #661503] Wed, 22 March 2017 02:39 Go to previous messageGo to next message
flyboy
Messages: 1856
Registered: November 2006
Senior Member
Hi,

I am not sure what exactly you mean with "join", but as the posted query sample is selecting only columns from the table A, using EXISTS/IN conditions and their proper combination (you would not "simulate" OR, just use it directly) should suffice.

[Edit: grammar, terminology]

[Updated on: Wed, 22 March 2017 02:41]

Report message to a moderator

Re: Conditional Join Logic [message #661510 is a reply to message #661503] Wed, 22 March 2017 03:35 Go to previous message
John Watson
Messages: 7669
Registered: January 2010
Location: Global Village
Senior Member
And a third solution - use a compound query: join to one table and UNION with a join to the other table.
Previous Topic: need help in setting constraints for the column based on subquery (2 threads merged by bb)
Next Topic: copy table structure
Goto Forum:
  


Current Time: Sun Nov 18 16:35:13 CST 2018