Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Conditional Join

Posted on 2012-08-28
3
Medium Priority
?
372 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Accepted Solution

by:
Ryan earned 2000 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 74

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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

609 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