Solved

Outer Join with Condition

Posted on 2012-04-02
3
367 Views
Last Modified: 2012-07-16
i am joining 2 tables ..... here i am writing the query

SELECT A.*,B.*
FROM MATL_MSTR A,
         MATL_PROD B,
         MATL_DISPATCH C
WHERE A.MATL_ID = B.MATL_ID AND
            A.MATL_ID = C.MATL_ID(+);

Here i want to put one more condition with the outer join table (MATL_DISPATCH) i.e C.matl_sts = '75'.

IF i am directly using this condition then i am not getting all matl_id. Please help me and explain me how to use a condition in outer join table and that should be executed only when the outer join table has the data for that matl_id.
0
Comment
Question by:chinmaya224
3 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 37799561
Not get what exactly you want
but as per understaning you want to include the data from table  MATL_DISPATCH C
if it excists with condition C.matl_sts = '75'

then try this

SELECT A.*,B.* , C.*
FROM MATL_MSTR A Inner join
         MATL_PROD B on A.MATL_ID = B.MATL_ID,
         Left join MATL_DISPATCH C On A.MATL_ID = C.MATL_ID and C.matl_sts = '75'
0
 
LVL 1

Accepted Solution

by:
leclaude earned 500 total points
ID: 37800948
Put Matl_Dispatch in a subquery.  This should do the trick.

SELECT A.*,B.*
FROM MATL_MSTR A,
         MATL_PROD B,
         (SELECT * FROM MATL_DISPATCH C WHERE C.MATL_STS='75') C
WHERE A.MATL_ID = B.MATL_ID AND
            A.MATL_ID = C.MATL_ID(+)
0
 

Author Closing Comment

by:chinmaya224
ID: 38190780
Thank You ..
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sql server query 12 32
Comparison query - 4 columns 9 42
Display field if column exists 7 31
how to make geography query faster?  SQL 7 41
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question