How Correlated Subquery work with JOIN

Hi, There,
I use Northwind database, and the codes below executed good.
      USE Northwind
      SELECT c.Country, o.OrderID, o.CustomerID, o.OrderDate
      FROM Orders o
      INNER JOIN Customers c
      ON o.CustomerID=c.CustomerID
      WHERE o.CustomerID IN(SELECT c.CustomerID FROM Orders WHERE Country ='Germany')
However, in the subquery,
(SELECT c.CustomerID FROM Orders WHERE Country ='Germany')
, if I replaced the "Orders" by "Customers",
, then the Country will not be filtered to Germany as I need.
I am curious to know why it cannot filter the Country in that way.
Appreciate you for your explanation!!

Hi TryToFly,
Based on my test, I can reproduce the same issue in my local environment.
To compare the difference between those two queries, we can see the Execution plans corresponding to the queries. Based on the Execution plans, I find this:
The first query: SELECT c.Country, c.CustomerID  FROM Customers c   WHERE Country =N'Germany'
                       SELECT o.OrderID, o.CustomerID, o.OrderDate, o.CustomerID  FROM Orders o
                       SELECT c.Country, o.OrderID, o.CustomerID, o.OrderDate  FROM Orders o  INNER JOIN Customers c  ON o.CustomerID=c.CustomerID
The second query: SELECT c.Country, c.CustomerID  FROM Customers c   
                            SELECT c.Country, c.CustomerID  FROM Customers c   
                            SELECT c.Country, o.OrderID, o.CustomerID, o.OrderDate  FROM Orders o  INNER JOIN
Customers c  ON o.CustomerID=c.CustomerID
                            SELECT c.CustomerID  FROM Customers c   WHERE Country =N'Germany'
                            SELECT c.Country, o.OrderID, o.CustomerID, o.OrderDate  FROM Orders o INNER JOIN Customers
c  ON o.CustomerID=c.CustomerID  WHERE o.CustomerID IN(SELECT c.CustomerID FROM Customers WHERE Country ='Germany')
According to the Execution plans, the results make sense.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support

Similar Messages

  • How do I work with FK in a data profile?

    Hello People:
    I am new in OWB tools and I have many doubts. Therefore, I would like to know if anyone can guide me a bit with the theme of FK and profiles.
    How do I work with FK in a data profile?
    If I have a table that has a FK to most of the tables, because it is like a parent table. What should I do to have that FK in the profile?
    e.g.
    - Table 1 FK Table 2
    - Table 1 FK Table 3
    - Table 1 FK Table 4
    - Table 1 FK Table 5
    - Table 1 FK Table 6
    - Table 2 FK Table 7
    - Table 2 FK Table 8
    - Table 8 FK Table 9
    You should have a data profile with each table or a data profile for all related tables?
    If I am all in a single profile, that it would have no problem but I would only slow every time that I have to add a new table, but if I got separated, I can not use the FK? What is the solution that will give this problem?
    e.g. PROFILE GENERAL
    - Table 1
    - Table 2
    - Table 3
    - Table 4
    - Table 5
    - Table 6
    - Table 7
    - Table 8
    - Table 9
    OR
    PROFILE 1 -> - Table 1
    PROFILE 2 -> - Table 2
    PROFILE 3 -> - Table 3
    PROFILE 4 -> - Table 4
    PROFILE 5 -> - Table 5
    PROFILE 6 -> - Table 6
    PROFILE 7 -> - Table 7
    PROFILE 8 -> - Table 8
    PROFILE 9 -> - Table 9
    OR
    PROFILE R -> Table 1 / Table 2
    PROFILE S -> Table 1 / Table 3
    PROFILE T -> Table 1 / Table 4
    PROFILE U -> Table 1 / Table 5
    PROFILE V -> Table 1 / Table 6
    PROFILE W -> Table 2 / Table 7
    PROFILE X -> Table 2 / Table 8
    PROFILE Z -> Table 8 / Table 9
    Thank you very much for your help!
    Best regard!

    Any idea, please?

  • My wife and I have separate Ids but all our music is in one library. How will this work with iCloud?

    My wife and I have separate Ids but all our music is in one library. How will this work with iCloud? i'm trying to download past purchases from her id, but itunes is saying that I can't because the computer is associated with my apple id. Can I associate the computer with both ids for the purpose of identifying all of our music with both or just one of our ids? Is there a good way to do this? I'm sure we're not the only people with this problem...
    Using 2 iphone 3gs, ipad, mac mini, appletv, itunes for windows, macbook, and imac.

    iTunes- How to share music between different user accounts on a single computer
    You cannot merge two separate libraries across user accounts. Photos does not have the function of merging different Photos.library files. If you have Aperture then you can merge the two before migrating over to Photos.

  • HT204053 My husband and I both have iPhones but we only have one iPad. We use the same apple ID because we also share the same email address. How would this work with iCloud because we don't share the same contacts?  Thanks Elainecontacts

    My husband and I both have an iPhone and we share an iPad. We also share the same email address so how would this work with iCloud because we don't share all the same contacts?
    Thanks

    An icloud account is designed to be used by one user.  That user can have all his/her devices synced with the same Apple data (email, contacts, calendars, notes, reminders, etc.) .  When two people use the same account, then problems usually occur when one user edits data that the other user doesn't want changed on their device.  You can continue sharing the same ID for the itunes account in order to share the purchased music, apps, etc.  itunes accounts and icloud accounts are different.
    It's by far better that each user has his/her own icloud account.

  • How does Remote work with Apple TV?

    How does Remote work with Apple TV?
    1. Does Remote, "Play" the music that resides on your iPod Touch>Apple TV>Home Speakers.
    OR
    Does Remote "Control" the music that resides on Apple TV HD>Home Speakers.
    (If so... say you have a iPod Touch that only holds 8GB's but your music collection on your Apple TV exceeds that amount.
    Will Remote still "Control" the larger music collection on Apple TV or your computer?)
    2. Will iPod Wifi work on a patio outside a home to control Apple TV inside the home?
    thank you in advance, Tom

    Remote is a way to control iTunes on either your computer or Apple TV using a WiFi connection. See this article for complete instructions.

  • How SEM BPS works with SAP BW

    Hi,
    How SEM BPS works with SAP BW.
    how to save planned in SAP BW.
    how to work with the data in Basic cubes and Transaction cubes.
    what is the relation between these two cubes.
    Thanks,
    cheta.

    hi,
    chk the link for BPS
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/7c85d590-0201-0010-20b5-f9d0aa10c53f
    Can any body send the material for BPS?
    Authorization for BPS
    Ramesh

  • How create and work with Z output to meet the client requirment?

    hi  gurus,
    I am SD functional consultant and need ur help
    Please explain me how create and work with Z output .
    How we arrange and change the fields in header and footer
    where and how we do changes in Layouts setting and SAP scripts to meet the user requirments.
    pls forward functional or Tech spec of Z output
    points will be rewarded
    thanx & regards
    shabnum

    Hi shabnum ,
    I hope you can do it.
    Goto SE71, enter form name--> click change
    1) click in page window command button, Identify the header and footer window
    2) single click on Header window and click change button(pencil symbol)
    3) identify the fields and change order of the fields
    I hope this will help to solve your issue
    Regards,
    SaiRam

  • How does it work with an iPad?

    Thinking about buying an Airport for my iPad to boost the wifi signal any know how the Airport works with an iPad? 

    An Airport will not boost a WiFi signal.  Period.
    An Airport can be configured to extend (repeat) a WiFi signal generated by another Airport.  This is done to extend the distance of the WiFi system but it does cause a loss of throughput (because of overhead).
    I wanted to get a WiFi signal out to my back porch.  I turned off the radio on my existing router (Westell) and purchased TWO Airport Express units.  One replaced the Westell radio and the other functions as an extender.  Works like a champ.

  • How to start working with iReport?

    Hi All,
    I'm just decide to use iReport for create report on Web but I don't know
    How to start working with iReport , What program I should to install , How
    to config any system files and set property .
    Please advice me for work with IReport.
    Thank you

    Hi,
    best hint to give is to start interviewing the product owner
    http://ireport.sourceforge.net/cap3.html
    Note that this is an open source project. Once you know which libraries you need, create a project in JDeveloper and double click on the project node. There is a Library node that allows you to import libraries to be used in your code.
    Under Tools --> Manage Libraries you can configure JSP tag libraries if required
    Frank

  • How create and work with Z output to meet user req

    hi gurus,
    I am SD functional consultant and need ur help
    Please explain me how create and work with Z output .
    How we arrange and change the fields in header and footer
    where and how we do changes in Layouts setting and SAP scripts to meet the user requirments.
    pls forward functional or Tech spec of Z output
    points will be rewarded
    thanx & regards
    shabnum

    Hi
    From SPRO do the all steps.
    Goto SD-> BASIC functions->Output control->Output determination->Output determination by condition technique->Maintain Output determination for sales documents
    Here define all like access sequences, Output types, condition tables and assign them to Program and Forms.
    From SE71 copy the script to a Zscript and to modify it to suit your requirements and the same Zscript has to be assigned to Output type, Program in NACE transaction.
    Reward points if useful
    Regards
    Anji

  • How can I work with my adobe Lightroom Version 5 which was added to my Samsung NX3000. If I want to load an .SRW File it is not possible, only the .JPG File. How and from where can I the Module and how is it to install ?

    How can I work with my adobe Lightroom Version 5 which was added to my Samsung NX3000. If I want to load an .SRW File it is not possible, only the .JPG File. How and from where can I the Module and how is it to install ?

    You need Lightroom 5.5 or later (the most current version is 5.7.1). This is a free update if you have already purchased an earlier version of Lightroom 5.
    Product updates

  • How Transaction Manager work with Resource Manager, like Connection pool?

    hi,
    I'm using BEA Webloigc8.1 Stateless Session Bean/DAO/Oracle stored proc.
    but I'm not quite clear how Transaction Manager work with Resource Manager, like Connection pool.
    my understanding is that, in a weblogic transaction, a stateless session bean interact with several DAOs, and for each method of DAO a connection is acquired from connection pool. I've heard that the connection will not return to pool until the transaction commits.
    My question is that, does it mean that for a weblogic transaction, multiple connections might be allocated to it? and if multiple connections are allocated, then how many oracle transactions would be started? or multiple connections share the same oracle transaction?
    I didn't feel it make sense to start multiple oracle transactions, cause deadlock might be incurred in a single weblogic transaction.
    any help appreciated!

    Xin Zhuang wrote:
    hi,
    I'm using BEA Webloigc8.1 Stateless Session Bean/DAO/Oracle stored proc.
    but I'm not quite clear how Transaction Manager work with Resource Manager, like Connection pool.
    my understanding is that, in a weblogic transaction, a stateless session bean interact with several DAOs, and for each method of DAO a connection is acquired from connection pool. I've heard that the connection will not return to pool until the transaction commits.
    My question is that, does it mean that for a weblogic transaction, multiple connections might be allocated to it? and if multiple connections are allocated, then how many oracle transactions would be started? or multiple connections share the same oracle transaction?
    I didn't feel it make sense to start multiple oracle transactions, cause deadlock might be incurred in a single weblogic transaction.
    any help appreciated!Hi. If you configure your WLS DataSource to use keep a connection for
    the duration of a tx, it will do that, and in any case there can be
    no deadlock however many connections operate for a given XA transaction.
    Here is the best coding form for DAOs or any other user-written code
    for using WebLogic DataSources. This is important for two reasons:
    1 - Thread-safety is maintained as long as the connection is a
    method-level object.
    2 - It is crucial to notify WebLogic that you are done with a connection
    ASAP, by your calling close() on it. We will then put it back in the
    pool, or keep it under the covers for your next request if it's in a
    transaction etc. The pool is optimized for quick get-use-close scenarios.
    public void one_of_my_main_JDBC_Methods()
    Connection con=null; // Must be a method level object for thread-safety
    // It will be closed by the end of the method.
    try {
    con = myDataSource.getConnection(); // Get the connection in the try
    // block, directly from the WebLogic
    // datasource
    // do all the JDBC within this try block. You can pass the
    // connection to subordinate methods, but not to anywhere
    // that thinks it can use the connection later.
    rs.close(); // close any result set asap
    stmt.close(); // then close any statement asap
    // When you're done with JDBC
    con.close(); // close the connection asap
    con = null; // nullify it so the finally knows it's done
    catch (Exception e) {
    // do whatever catch stuff you want. You don't
    // need a catch block if you don't want one...
    finally {
    // It is important to close a JDBC connection ASAP when it's not needed.
    // without fail, and regardless of exit path. Do everything in your
    // finally block in it's own try-catch-ignore so everything is done.
    try { if (con != null) con.close();} catch (Exception ignore){}
    return ret;
    }

  • How does QoS work with WAAS WCCP? What's the interaction between QoS Traffic Classification and WAE Traffic Application Policy?

    How does QoS work with WAAS WCCP? What's the interaction between Router QoS Traffic Classification and WAE Traffic Application Policy?

    By default, WAAS preserves the DSCP marking on intercepted packets.  There is a configuration option to set/override the DSCP value at the global (device), application, and classifier levels.  Currently WAAS provides marking only.  There is no action taken by WAAS based on the DSCP value.
    Regards,
    Zach

  • How do we work with creative cloud on a citrix platform?

    We are licensed creative cloud users. How do we work with creative cloud on a citrix platform?
    we have architects who work on revit but they need to access creative cloud suite whilst still in Revit via citrix server.
    How does she do that? please does anybody know?

    Contact Adobe. Creative Cloud is working fine here with 10.9.1.

  • I have a Powerbook G4 (don't laugh) with iPhoto '08. How does iCloud work with my computer. I have a iPhone 4 that has iCloud.

    I have a Powerbook G4 (don't laugh) with iPhoto '08. How does iCloud work with my computer. I have a iPhone 4 that has iCloud. Is iCloud pushing my phone's PhotoStream to my computer if it doesn't have the latest OS? Thanks so much for whoever can help!

    iCloud will not work with your computer because iCloud requires Lion. Lion requires an Intel Core 2 Duo processor or better. For you to have iCloud and PhotoStream you would need to buy a newer Mac Intel model meeting the requirements for Lion:
    Lion System Requirements
    Mac computer with an Intel Core 2 Duo, Core i3, Core i5, Core i7, or Xeon processor
    2GB of memory
    OS X v10.6.6 or later (v10.6.8 recommended)
    7GB of available space
    Some features require an Apple ID; terms apply.

Maybe you are looking for

  • Problems pasting pages from another document

    Hi guys, I used to copy pages from one ID document to another very easily before. I don't know why i cannot do it now. I have both InDesign CS 6 files. I open them both in two separated windows but when i select copy from page 3 (the short 6 pages Ne

  • How to export the source from a Jdeveloper to another Jdeveloper?

    Help me. In my company I have begun to write a Java Web Application with Struts using Jdeveloper. I have the necessity to move all the project in my laptop, work on it and after move another time the project into the PC of my firm and so on. How i ca

  • Quries in portal takes long time.

    HI When I execute the queries in Bex it gives the output in seconds.Howeve when i see the reports in Portal it taking around 2 hrs to display the report. Web Template published in the protal is a combination of diffrent queries Please suggest the to

  • Mirror file??

    hi I'm having a tidy up og my hard drive, and I just found a huge (10g) file in my user/library/mirrors that appears as my user name and a .dmg tag Any ideas on what this might be, when i try and open it Omnioutliner opens but no info given regards S

  • DHCP failover not working

    I am attempting to implement DHCP failover using load balancing with an Essentials and a Standard server.  I have everything configured and working but I am facing an issue. If I try to start the DHCP services on the Essentials server and the DHCP se