Solved

Conditional Join

Posted on 2012-08-28
3
364 Views
Last Modified: 2012-08-28
Hello experts,

I have this conditional join right here, thanks to the help of the community yesterday

INSERT INTO shipping(sdate, rec_wh, shipping, item)
    SELECT ship_date, receiver_warehouse, ord, custitemcode
      FROM wag
     WHERE     custitemcode = 'SOME ITEM'
           AND (SELECT SUM(ord)
                  FROM recinc
                 WHERE in_item = 'SOME ITEM') = (SELECT SUM("tSHIPPING")
                                                   FROM trans
                                                  WHERE "tITEM" = 'SOME ITEM');

Open in new window


While this achieves what I am trying to do when i use the variable 'SOME ITEM'

I need this to be accomplished on all items in that column that match the above statement. I have tried different variations of the above and it does not work


so lets say in columns, IN_ITEM and t_ITEM have 'SOME ITEM' and other items (eg, 'some item2' 'some item3' etc etc

i want this to happen to all rows where column data matches
0
Comment
Question by:futureDBA
3 Comments
 
LVL 13

Accepted Solution

by:
MrBullwinkle earned 500 total points
ID: 38341768
I'm not really sure I follow what you're asking, but does the following work?  I replaced SOME ITEM, with a reference to CustItemCode, and removed that filter.  You also had quotes around field names, which I removed.

INSERT INTO shipping(sdate, rec_wh, shipping, item)
    SELECT ship_date, receiver_warehouse, ord, custitemcode
      FROM wag
           WHERE (SELECT SUM(ord)
                  FROM recinc
                 WHERE in_item = wag.custitemcode) = (SELECT SUM(tSHIPPING)
                                                   FROM trans
                                                  WHERE tITEM = wag.custitemcode);
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 38341790
tITEM and tSHIPPING are mixed case, you'll need to restore the quotes taken out above


SUM("tSHIPPING")

WHERE "tITEM" = wag.custitemcode);


otherwise oracle will treat them as columns with names TSHIPPING and TITEM which don't exist in your table


also note, if you still want to apply a filter to the wag table, then apply it there by adding a clause like this to end of the query...

AND wag.custitemcode in ('SOMEITEM','some_other_item','a_third_ITEM')
0
 

Author Closing Comment

by:futureDBA
ID: 38342123
Thank You sir, perfect
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle Subquery bad Join 11 59
Insert and update a row at the same time 4 49
Oracle - Create Procedure with Paramater 16 56
How to free up undo space? 3 26
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to recover a database from a user managed backup

919 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now