Difference between these queries

Hi,
I have two tables table1 and table2. Both have a common column say for ex. col1
I tried to find the rows in table1 where there is no corresponding value for col1.
My query is
Select * from table1 a where a.col1 not in (select b.col1 from table2 b);
This returned me nothing.
But when my co-worker executed a query like this
select a.col1 from table1 a
minus
select b.col1 from table2 b;
This gave us the results. How is both of them different and how to know where to use what?

Hi,
where   a.col1 not in (select b.col1 from table2 b);will never evaluate to TRUE if there are NULLs in table2.col1.
Remember that SQL uses three-valued logic.
Expressions such as x IN (y) can be TRUE, FALSE, or UNKNOWN.
Since x = NULL is UNKNOWN (even if x itself IS NULL), then x IN (y), where y is a list or a sub-query, will be either TRUE or UNKNOWN if y contains NULL.
So x NOT IN (y) will be either FALSE or UNKNOWN (if y contains NULL).
To be practical, NOT IN sub-queries usually need to guarantee that they will not return NULL rows, e.g.
WHERE   a.col1 NOT IN
        SELECT  col1
        FROM    table2
        WHERE   col1 IS NOT NULL
        )Repeat: this applies only to NOT IN sub-queries.
IN sub-queries behave the way most people find intuitive.

Similar Messages

  • Whats the difference between these two queries ? - for tuning purpose

    Whats the difference between these two queries ?
    I have huge amount of data for each table. its takeing such a long time (>5-6hrs).
    here whice one is fast / do we have any other option there apart from listed here....
    QUERY 1: 
      SELECT  --<< USING INDEX >>
          field1, field2, field3, sum( case when field4 in (1,2) then 1 when field4 in (3,4) then -1 else 0 end)
        FROM
          tab1 inner join tab2 on condition1 inner join tab3 on condition2 inner join tab4 on conditon3
        WHERE
         condition4..10 and
        GROUP BY
          field1, field2,field3
        HAVING
          sum( case when field4 in (1,2) then 1 when field4 in (3,4) then -1 else 0 end) <> 0;
    QUERY 2:
       SELECT  --<< USING INDEX >>
          field1, field2, field3, sum( decode(field4, 1, 1, 2, 1, 3, -1, 4, -1 ,0))
        FROM
          tab1, tab2, tab3, tab4
        WHERE
         condition1 and
         condition2 and
         condition3 and
         condition4..10
        GROUP BY
          field1, field2,field3
        HAVING
          sum( decode(field4, 1, 1, 2, 1, 3, -1, 4, -1 ,0)) <> 0;
    [pre]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    My feeling here is that simply changing join syntax and case vs decode issues is not going to give any significant improvement in performance, and as Tubby points out, there is not a lot to go on. I think you are going to have to investigate things along the line of parallel query and index vs full table scans as well any number of performance tuning methods before you will see any significant gains. I would start with the Performance Manual as a start and then follow that up with the hard yards of query plans and stats.
    Alternatively, you could just set the gofast parameter to TRUE and everything will be all right.
    Andre

  • Differences between these statements

    Could you please let me know the exact difference between these two statements?
    ALTER SESSION ENABLE PARALLEL QUERY;
    ALTER SESSION FORCE PARALLEL QUERY PARALLEL 16;In the second one we can control the number of parallel threads .
    Is there any other difference between these two?
    Thanks in advance!
    Edited by: Pandeesh on Feb 12, 2013 8:26 AM
    Edited by: Pandeesh on Feb 12, 2013 8:27 AM

    >
    Thanks! I checked the documentation just now.
    >
    I don't understand how you could have checked the documentation if you still don't understand what the word FORCE adds to things.
    I just checked the documentation and it seems pretty clear to me.
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_2012.htm
    >
    ENABLE Clause
    Specify ENABLE to execute subsequent statements in the session in parallel. This is the default for DDL and query statements.
    •DML: DML statements are executed in parallel mode if a parallel hint or a parallel clause is specified.
    •DDL: DDL statements are executed in parallel mode if a parallel clause is specified.
    •QUERY: Queries are executed in parallel mode if a parallel hint or a parallel clause is specified.
    Restriction on the ENABLE clause You cannot specify the optional PARALLEL integer with ENABLE.
    DISABLE Clause
    Specify DISABLE to execute subsequent statements in the session serially. This is the default for DML statements.
    •DML: DML statements are executed serially.
    •DDL: DDL statements are executed serially.
    •QUERY: Queries are executed serially.
    Restriction on the DISABLE clause You cannot specify the optional PARALLEL integer with DISABLE.
    FORCE Clause
    FORCE forces parallel execution of subsequent statements in the session. If no parallel clause or hint is specified, then a default degree of parallelism is used. This clause overrides any parallel_clause specified in subsequent statements in the session but is overridden by a parallel hint.
    •DML: Provided no parallel DML restrictions are violated, subsequent DML statements in the session are executed with the default degree of parallelism, unless a degree is specified in this clause.
    >
    This is the DML bullet point for ENABLE
    >
    •DML: DML statements are executed in parallel mode if a parallel hint or a parallel clause is specified.
    >
    And this is the one for FORCE
    >
    FORCE forces parallel execution of subsequent statements in the session. If no parallel clause or hint is specified, then a default degree of parallelism is used.
    >
    The word ENABLE does just what you would expect it to do: it ENABLEs (allows) parallel to be used. Parallel will be used if, as the doc quote says, 'a parallel hint or a parallel clause is specified'.
    The word FORCE does just what you would expect it to do: it FORCEs parallel to be used. As the doc quote says 'FORCE forces parallel execution of subsequent statements in the session. If no parallel clause or hint is specified, then a default degree of parallelism is used.'.
    With FORCE parallel WILL be used. With ENABLE parallel MAY be used.
    If you still don't understand the difference then please explain what it is you are having trouble with.

  • What is the difference between these two reports MC.1 and MB5L

    Hi
    what is the difference between these two reports MC.1 and MB5L?
    what is the Purpose of each report?
    Material ledger is activated for this plant, we found some amount difference between these two reports, my client accounting department used to compare these two reports while year end/month end closing
    Thanks
    Raju

    MC.1 will give you the report for plant analysis as per plant .
    MB5L report will give you list of stock value as per G/L account wise.

  • Difference between these Thunderbolt cables for an iMac?

    What is the difference between these two Thunderbolt cables for connecting Thunderbolt harddrive docking station to an iMac?
    http://store.apple.com/us/product/MD862ZM/A/apple-thunderbolt-cable-05-m
    http://store.apple.com/us/product/MD861ZM/A/apple-thunderbolt-cable-20-m
    Thanks!

    Along the lines of this topic, does anyone know whether Mini DisplayPort cables are usable for Thunderbolt? Here's one, for example, that's cheaper than Apple's $29 cable:
    http://www.amazon.com/exec/obidos/ASIN/B009NE77TQ/
    I would be concerned about (at least) two things:
    1. Can it handle the speed?
    2. Does it have the right circuit?
    It's possible that if it *seems* to work in a thunderbolt application, you might still run into trouble with intermittent data failure if it's not up to the task.
    Thanks for any thoughts.

  • Color differences between these two files?

    Could someone please tell me the color differences between these two files? What are the differences in general of these two files and how do I make a file identical to the blue cancel button?
    I am working with signature pads and the BLUE CANCEL image works, but the other GREEN image does not. Both are 8-bit .bmp files... HELP!

    #1, obviously, would be to connect a mic that doesn't require phantom power.
    And #2 comes with a 6 ft. USB cable, so you may not need a bunch more cables. Maybe just one standard XLR to connect a mic to it.
    Message was edited by: p o'flynn

  • Difference between these 2 Laptops: X201 / T410 : Links

    Hello
    I dont see any difference between these 2 :/. ( Power/Display...)
    http://cgi.ebay.fr/LENOVO-THINKPAD-T410-i7-620M-2-66Ghz-4GB-320GB-7-2K-/190456687118?pt=Laptops_Nov0...
    http://cgi.ebay.fr/LENOVO-THINKPAD-X201-i7-620M-2-66GHZ-4GB-RAM-500GB-7-2K-/190456645897?pt=Laptops_...
    Which one is the best?
    Thks

    Hi stevekho,
    Besides obvious differences in the specs, I think it's more like which one best meets your requirement because one is an ultraportable with 12 inch screen and the other performance thinkpad with 14 inch display. X201 doesn't come with optical drive, whereas T410 does. There may be other differences too like internal features etc. in order to find out I would suggest consulting this:- ThinkPad Notebooks
    If I were you I would read the reviews first, and decide based on which one would greatly accommodate my needs, you can read reviews at following links:-
    Lenovo ThinkPad X201 Review
    Lenovo ThinkPad T410 Review
    Hope it helps.
    Maliha (I don't work for lenovo)
    ThinkPads:- T400[Win 7], T60[Win 7], IBM 240[Win XP]
    IdeaPad: U350
    Apple:- Macbook Air [Snow Leopard]
    Did someone help you today? Compliment them with a Kudos!
    Was your question answered today? Mark it as an Accepted Solution! 
      Lenovo Deutsche Community     Lenovo Comunidad en Español 
    Visit my YouTube Channel

  • Whats the difference between these versions of photoshop?

    First of all to make things clear I want to mention this first that I lives in Pakistan and Adobe doesn't support my region so in order to buy the Adobe Photoshop CC I have to contact the authorized resellers, after contacting them and asking for a invoice proposal for Adobe Photoshop CC, they send me several invoice proposals (per user team liscense). But I just got in a trouble as these proposals are offering Photoshop CC different versions so its like kinda making me double mind, i am just confused which to buy as prices are differ too and kinda noticeable. As for making my intentions clear I also wanna mention that I am looking for Single App Liscense i mean i just wanna buy Photoshop CC thats it. But for sure its not gonna be that photography version nor student one. Also i wanna know that whats the difference between these two versions and also tell me the pros and cons.
    So please help me choose which one is better for me as I am really confused with it.
    Here are the links
    Note: You will have to translate these pages into english
    Link one:
    [65224660BA01A12] ราคาพิเศษ จำหน่าย Photoshop CC ALL Multiple Platforms Multi Asian Languages Licensing Subscription Mo…
    Link two:
    [65226001BA01A12] ราคาพิเศษ จำหน่าย Photoshop CC ALL Multiple Platforms Multi Asian Languages Licensing Subscription Mo…
    I've attached screenshots too

    The features in both of the Photoshop CC are identical, there is a difference in price because, the higher priced is the original Photoshop price, the less priced is the promotional priced Photoshop CC eligible only if you have CS3 or later version of Adobe creative suite product.
    Hope this answers your question.
    Regards
    Rajshree

  • How to get the difference between these two dates

    Hello Friends,
    I need to get the difference between these two fields which store dates but with varchar2 data types
    SELECT pac.segment1, pac.segment2 emp_no, pac.segment3 NAME,
    pac.segment4 POSITION, pac.segment5 start_date, pac.segment6,
    pac.segment7
    FROM per_analysis_criteria pac, fnd_id_flex_structures_vl ffs
    WHERE ffs.id_flex_structure_code = 'Employee Rejoin'
    AND ffs.id_flex_num = pac.id_flex_num
    AND TO_CHAR (TO_DATE (pac.segment7, 'YYYY/MM/DD HH24:MI:SS'))
    - TO_CHAR (TO_DATE (pac.segment6, 'YYYY/MM/DD HH24:MI:SS')) > 1;
    my query is something like this...
    am trying to find the difference between the last two columns but with not much luck..
    can some one suggest me a solution please

    SELECT pac.segment1, pac.segment2 person_id, pac.segment3 NAME,
    papf.employee_number, paaf.supervisor_id, pac.segment4 POSITION,
    pac.segment5 start_date, pac.segment6, pac.segment7,
    papf2.email_address,
    ( TO_DATE (TO_CHAR (pac.segment7), 'DD-MON-YYYY HH:MI:SS AM')
    - TO_DATE (pac.segment6, 'DD-MON-YYYY HH:MI:SS AM')
    + 1
    ) difference,
    POST.email_address
    FROM per_analysis_criteria pac,
    apps.fnd_id_flex_structures_vl ffs,
    per_all_people_f papf,
    per_all_assignments_f paaf,
    per_all_people_f papf2,
    (SELECT email_address, person_id
    FROM per_all_people_f
    WHERE person_id IN (
    SELECT person_id
    FROM per_all_assignments_f
    WHERE position_id IN (SELECT position_id
    FROM per_positions
    WHERE NAME LIKE 'HR Manager.704.')
    AND TRUNC (SYSDATE) BETWEEN effective_start_date
    AND effective_end_date)
    AND TRUNC (SYSDATE) BETWEEN effective_start_date AND effective_end_date
    AND business_group_id = fnd_profile.VALUE ('PER_BUSINESS_GROUP_ID')) POST
    WHERE ffs.id_flex_structure_code = 'Employee Rejoin'
    AND TO_CHAR (papf.person_id) = pac.segment2
    AND ffs.id_flex_num = pac.id_flex_num
    AND TRUNC (SYSDATE) BETWEEN papf.effective_start_date
    AND papf.effective_end_date
    AND papf.current_employee_flag = 'Y'
    AND papf.person_id = paaf.person_id
    AND TRUNC (SYSDATE) BETWEEN paaf.effective_start_date
    AND paaf.effective_end_date
    AND papf.person_id = paaf.person_id
    AND papf2.person_id = paaf.supervisor_id
    AND paaf.primary_flag = 'Y'
    AND TRUNC (SYSDATE) BETWEEN papf2.effective_start_date
    AND papf2.effective_end_date
    AND papf2.current_employee_flag = 'Y'
    and ( TO_DATE(to_char(pac.segment7), 'DD-MON-YYYY HH:MI:SS AM')-TO_DATE (pac.segment6, 'DD-MON-YYYY HH:MI:SS AM')+1) >1
    last line is giving me the error pls suggest a solution

  • What is the difference between these two instant ink printers?

    Looking to get one of the HP instant ink printers from Best Buy. Either the Envy 4500 or the Envy 5530. There is a $20 diference and I did a side-by-side comparison of them on the Best Buy site, but the only difference I can notice is the 5530 seems to have more memory than the 4500 (128MB vs 32MB).
    Print speeds and resolutions seem to be the same. The cheaper one (4500) also seems to be able to do two-sided printing & reduction/enlargement (which I would have thought to be on the more expensive mode). So are there any other real differences between these two or have I pretty much covered them all?

    HI - great question, you identified a few of the differences.  Some additional differences are:
    4500 has a monochome display that is not touch enabled (you have to use scroll buttons on the side of the screen)
    5300 has a touch enabled color display
    Both printers can do duplexing (printing on both sides) and both have wireless.  
    We are excited about Instant Ink  and hope you enjoy the service & whichever printer you chose!  
    Although I am an HP employee, I am speaking for myself and not for HP

  • Difference between these models?

    whats the difference between these ipad 16gb wifi's?
    mb292ll/a
    and
    mc820ll/a

    Most likely where they are sold.

  • What is the Difference Between these IF statements

    Hello
    Can someone tell me the difference between these two IF statements.
    -- IF STATEMENT 1--
    IF v_transcode not in ('A','C','D') THEN
    raise_application_error (-20000, 'Error Invalid Transcation Code');
    END IF;
    -- IF STATEMENT 2 --
    IF v_transcode <> 'A' AND v_transcode <> 'C' AND v_transcode <> 'D' THEN          
    raise_application_error (-20000, 'Error Invalid Transcation Code');
    END IF;
    Thanks

    Your if condition wherein you do
    v_transcode <> 'A' and v_transcode <> 'C' and v_transcode <> 'D'.
    I would think this is more better in terms of performance, because if the first clause (v_transcode <> 'A') fails nothing else needs to be evaluated, and it can skip the if condition there itself,
    but in case of
    v_transcode not in ('A', 'C','D'),
    it has to scan through the entire list.
    On the other side, if you have just 2 or 3 values to compare this makes sense, otherwise we may have to use the in operator.
    --Bhargavi                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • What is the difference between these setter methods

    What is the difference between these two setter methods??
    <jsp:useBean id="checking" scope="session" class="bank.Checking" />
    <jsp:setProperty name="checking" property="balance" value="0.0" /> and
    <jsp:useBean id="checking" scope="session" class="bank.Checking" >
    <jsp:setProperty name="checking" property="balance" value="0.0" />
    </jsp:useBean>

    Homework question?
    The answer is on this page (Step 5)
    http://java.sun.com/products/jsp/syntax/1.2/syntaxref1217.html#8865

  • What is the Difference between these Two?

    Hi All,
    In Oracle University site i saw 2 Courses for Oracle Webcenter sites. Just i would like to know the difference between these two. Based on your input i can decide which one to take.
    *1. Oracle Webcenter Sites for Developers*
              http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=609&p_org_id=1001&lang=US&get_params=dc:D73886GC10,p_preview:N
    *2. Oracle Webcenter Sites 11g for Developers*
              http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=609&p_org_id=1001&lang=US&get_params=dc:D78300GC10,p_preview:N
    Is the 1st one is Fatwire and the 2nd one is Fatwire+Oracle latest implmentation ? Is my understanding is right?
    regards
    Sri

    It's the same lens, just different sellers.  The higher one is the MSRP, or close to it.  But since they use this lens in a kit it goes for less.  I have no idea who Celltime Inc is, but it's fullfilled by Amazon, so I'd feel reasonably safe.  Just look into their return policy.
    With the recent release of the 6D and somewhat recent 5d3, the market is flooded with these lenses from kits; I wouldn't pay more than 800 something for it.  Getting it through Amazon is a bonus over eBay.  If the seller checks out I'd go for it.
    Edit: DH beat me to it. 

  • What is the difference between these two sticks of RAM?

    I am upgrading my Macbook 2.2 GHz Intel Core 2 duo from 2GB of ram to 4GB
    What is the difference between these two kits?
    4GB Kit (2 x 2GB) 200 Pin DDR2-667 PC2-5300 256x64 CL5 1.8V SODIMM ($102.00)
    4GB Kit (2 x 2GB) eRam 200 Pin DDR2-667 PC2-5300 CL5 1.8V SODIMM ($88.00)

    Probably nothing of any consequence. Some places can just negotiate better deals with suppliers. Or one of a million other factors that can affect price is in play here.
    When buying RAM, I generally find it's better to pay a little extra to get a brand that's known for quality. I usually stick to Crucial myself. If you look around, you can probably find some real steals out there, but I don't know... With stories of people who literally go dumpster diving, salvaging stuff that was slated for disposal, then turning around and selling it... I prefer not to take chances. If you are, by all means, go for the cheaper one.

Maybe you are looking for

  • Mixing Ram Sizes in Triple-Channel

    I would like to install 10 GB of RAM in the following configuration on my 2009 Mac Pro (flashed to 5,1): Slot 1:  4GB Slot 2:  4GB Slot 3:  2GB All 3 dimms are Apple OEM Hynix brand.  All are 1333MHz. Will this arrangement take advantage of the tripl

  • ITunes Has Stopped Working (10.3.1)?

    So before I downloaded the new iTunes, it kept saying "iTunes has stopped working." when I tried to open it. After multiple tries, I finally resorted to uninstalling it, and installing the new version. Still, it says "iTunes has stopped working." I t

  • Keeping the right site tied to my short url on MobileMe

    I have maintained multiple websites in multiple domain files, all published to MobileMe since iWeb first came out. I have one site which serves as an index page to all the sites I maintain. This index site is designed to be tied to my short url at Mo

  • Issue while creating a enhancement window with Interface enabled check

    Hello everyone, i have a standard webdynpro component "fmca_wdy_return" to enhance. The component is one the applications configured in floor plan manager "FPM_OIF_COMPONENT". we have created a tab on the FPM view and we need to configure the wda com

  • Doubt in abap coding

    Hi Experts, I have doubt, i have an internal table with four column. like below. KSCHL     VALUE      DIFF ZMBO     1.25     12.56 ZMBO     2.31     12.56 ZMBO     4     12.56 ZMBO     5     12.56 ZCHL     4.31     16.87 ZCHL     5.21     16.87 ZCHL