Use of double Minus operator....

Hi ,
I have a situation where i need to use the minus operator in such a way that:
<sql_statement_A>
Minus
<sql_statement_B>
Minus
<sql_statement_C>
The resulting row set will return rows from sql_statement_A minus rows from sql_statement_B or sql_statement_A minus rows from sql_statement_C... Is the above sql pattern is correct....or , do i need to write two views
<sql_statement_A>
Minus
<sql_statement_B>
and
<sql_statement_A>
Minus
<sql_statement_C>
and one third making Union of the two above...????
many thanks,
Simon

If in doubt, use parentheses to make them run the way you want.
So..
(<sql_statement_A>
minus
<sql_statement_B>)
minus
<sql_statement_C>
Just like OR conditions in the where clause, grouping with parentheses will greatly help those who come later to maintain it. And this looks simpler and more efficient than using two minus operations and combining the result.

Similar Messages

  • Error using minus operator

    table a
    =========
    id (number),name varchar2,dt date
    10,'aaa','01-01-2006'
    11,'bbb','01-01-2007'
    table b
    ======================
    id varchar2,name varchar2,dt varchar2
    '10','aaa','01-01-2006'
    is it possible to find out which row is not in table b but it is in table a
    i have tried out using minus operator but it return error (ora-01790-expression must have same datatype.

    ora-01790-expression must have same datatypeAnd what is it precisely is it about that error message which is confsuing you?
    SQL> select 1 from dual
      2  minus
      3  select dummy from dual
      4  /
    select 1 from dual
    ERROR at line 1:
    ORA-01790: expression must have same datatype as corresponding expression
    SQL> select to_char(1) from dual
      2  minus
      3  select dummy from dual
      4  /
    T
    1
    SQL> Cheers, APC

  • Using the minus operator

    I am very new to oracle and am working with the minus operator to run a query. I could use some help!
    Here is the query I am working on:
    select suppliername, partname
    from quote
    where partname = 'hammer'
    minus
    select suppliername, partname
    from quote
    where partname = 'hammer';
    HOW DO I GET THE QUERY TO DISPLAY ONLY THE ROWS OF SUPPLIERNAMES THAT SUPPLY ONLY HAMMERS?
    I WOULD GREATLY APPRECIATE SOME CLARIFICATION.

    HOW DO I GET THE QUERY TO DISPLAY ONLY THE ROWS OF SUPPLIERNAMES THAT SUPPLY ONLY HAMMERS?It may, for some data related reason, give you the result you were expecting, but this query does not answer that question because you have included partname in the MINUS.
    E.g.
    WITH quote AS
    (SELECT 'BOB'  suppliername, 'HAMMER' partname FROM DUAL UNION ALL
    SELECT 'BOB'  suppliername, 'SPANNER' partname FROM DUAL UNION ALL
    SELECT 'TIM'  suppliername, 'HAMMER' partname FROM DUAL UNION ALL
    SELECT 'JACK' suppliername, 'HAMMER' partname FROM DUAL)
    SELECT suppliername, partname
    FROM   quote
    MINUS
    SELECT suppliername, partname
    FROM   quote
    WHERE  partname != 'HAMMER';
    SUPPLIERNAME PARTNAME
    BOB          HAMMER  
    JACK         HAMMER  
    TIM          HAMMER   Clearly this is wrong because Bob supplies spanners (aka wrench).
    However:
    WITH quote AS
    (SELECT 'BOB'  suppliername, 'HAMMER' partname FROM DUAL UNION ALL
    SELECT 'BOB'  suppliername, 'SPANNER' partname FROM DUAL UNION ALL
    SELECT 'TIM'  suppliername, 'HAMMER' partname FROM DUAL UNION ALL
    SELECT 'JACK' suppliername, 'HAMMER' partname FROM DUAL)
    SELECT suppliername
    FROM   quote
    MINUS
    SELECT suppliername
    FROM   quote
    WHERE  partname != 'HAMMER';
    SUPPLIERNAME
    JACK        
    TIM          Amongst the many alternatives - NOT EXISTS:
    WITH quote AS
    (SELECT 'BOB'  suppliername, 'HAMMER' partname FROM DUAL UNION ALL
    SELECT 'BOB'  suppliername, 'SPANNER' partname FROM DUAL UNION ALL
    SELECT 'TIM'  suppliername, 'HAMMER' partname FROM DUAL UNION ALL
    SELECT 'JACK' suppliername, 'HAMMER' partname FROM DUAL)
    SELECT *
    FROM   quote q1
    WHERE  NOT EXISTS (SELECT 1
                       FROM   quote q2
                       WHERE  q2.suppliername = q1.suppliername
                       AND    partname != 'HAMMER');
    SUPPLIERNAME PARTNAME
    JACK         HAMMER  
    TIM          HAMMER  

  • MINUS Operator in OBIEE 11g

    Hi all ,
    I have a requirement to use MINUS operator in a column of a report . Since it is available for two separate criteria , Could someone suggest how to perform the same in OBIEE 11g for a column.
    the conditions to be implemented in a column are
    select count(*) from ( 
    select distinct trx.shipment_header_id
    from   
    F_ERP_PO_RECEIPTS_TRX trx
    where   trx.transaction_type = 'RECEIVE'
    MINUS
    select distinct rec.shipment_header_id
    from   
    where   trx.transaction_type = 'DELIVER').
    How can i perform these conditions for a column of a report .
    Reg,
    Niv D

    Hi Niv D,
    I guess this can be done as we have union, union all and minus available.
    once you select the required subject area say SA for the below query,
    select distinct trx.shipment_header_id
    from 
    F_ERP_PO_RECEIPTS_TRX trx
    where   trx.transaction_type = 'RECEIVE'
    on the right side of the criteria you can see a + symbol with venn diagram. once you click on it, it gives you an option to select the next SA for
    select distinct rec.shipment_header_id
    from 
    where   trx.transaction_type = 'DELIVER').
    once you selected that, you can see the criteria changes accordingly.
    there you change to union or minus.
    once you have the conditions for both, make the layout as pivot and apply count on the column. you are there with the result,
    I tried earlier with union but not with minus. but this should work.
    Regards,
    KN
    ebs2obiee.wordpress.com

  • Minus operator versus 'not exists' for faster SQL query

    Hi everybody,
    Does anyone know if rewriting a query to use the MINUS operator instead of using NOT EXISTS in the query is faster, giving all else is the same?
    Thanks very much!
    Bill Loggins
    801-971-6837
    [email protected]

    It really depends on a bunch of factors.
    A MINUS will do a full table scan on both tables unless there is some criteria in the where clause of both queries that allows an index range scan. A MINUS also requires that both queries have the same number of columns, and that each column has the same data type as the corresponding column in the other query (or one convertible to the same type). A MINUS will return all rows from the first query where there is not an exact match column for column with the second query. A MINUS also requires an implicit sort of both queries
    NOT EXISTS will read the sub-query once for each row in the outer query. If the correlation field (you are running a correlated sub-query?) is an indexed field, then only an index scan is done.
    The choice of which construct to use depends on the type of data you want to return, and also the relative sizes of the two tables/queries. If the outer table is small relative to the inner one, and the inner table is indexed (preferrable a unique index but not required) on the correlation field, then NOT EXISTS will probably be faster since the index lookup will be pretty fast, and only executed a relatively few times. If both tables a roughly the same size, then MINUS might be faster, particularly if you can live with only seeing fields that you are comparing on.
    For example, if you have two tables
    EMPLOYEE
    EMPID      NUMBER
    NAME       VARCHAR2(45)
    JOB        VARCHAR2(45)
    HIRE_DATE  DATE
    and
    RETIREE
    EMPID      NUMBER
    NAME       VARCHAR2(45)
    RET_DATE   DATEIf you wanted to see if you had retirees that were not in the employee table, then you could use either MINUS or NOT EXISTS (or even NOT IN, but you didn't ask). However you could possibly get different results.
    SELECT empid,name
    FROM retirees
    MINUS
    SELECT empid,name
    FROM employeeswould show retirees not in the emp table, but it would also show a retiree who had changed their name while retired. A safer version of the above using MINUS would be
    SELECT empid,name
    FROM retirees
    WHERE empid IN (SELECT empid
                    FROM retirees
                    MINUS
                    SELECT empid
                    FROM employees)A full scan of retirees, a full scan of employees (Assuming indexes on both, then maybe an index fast full scan) and two sorts for the minus, at best an index probe then table access by rowid on retirees, possibly a full scan of retirees for the outer query.
    Assuming that employees is indexd on empid then
    SELECT empid,name
    FROM retirees
    WHERE NOT EXISTS (SELECT 1
                      FROM employees
                      WHERE retirees.empid = employees.empid)requires a full scan of retirees and an index access into employees index for each row.
    As with most things SQL, the only real way to tell is to benchmark.
    HTH
    John

  • The MINUS operator in SQL

    Hi
    i use this minus operator to find the non matching row of the second query.
    after looking at the reasult of this query , i searched the one result in the second query alone i could see the data.
    it's worng The MINUS query returns all rows in the first query that are not returned in the second query.
    in my case it's returning the rows which returned by the second query.
    (select distinct lower(trim(to_char(sso))),lower(trim(to_char(region))),to_date(expiration_date,'DD-MM-YY') from ca_ourc_view
    where rownum <1001
    minus
    (select distinct lower(trim(to_char(sso))),lower(trim(to_char(region))),to_date(expiration_date,'DD-MM-YY') from ourc_members_v1@gesprd
    where rownum <1001
    )thanks
    Raj

    in my case it's returning the rows which returned by the second query.can't happen like this
    for example
    SQL> select * from scott.emp where empno=7369
      2  minus
      3  select * from scott.emp where empno=7499;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20

  • Minus operations on table

    Hi everyone,
    I am trying to find a way to do minus operations on table. I know this is possible in SQL, but I have yet to find out how to do it in ABAP. Can anyone help?
    What I need to do is the following.
    Let table A = (A,B,C,D,E) and table B = (B,C,E), then A minus B would return (A,D). Is there a function in ABAP for this?
    Thank you very much in advance.
    Philip R. Jarnhus

    hello,
    u can use subqueries:
    http://help.sap.com/saphelp_NW04/helpdata/en/dc/dc7614099b11d295320000e8353423/content.htm
    it is easy, but wrong way to solve your problem. This select will make a lot of calls to your DB.
    better way:
    1) two selects from table 1 and table 2 into two different internal tables.
    define two internal tables in your code. One table should have standard tables type and another hashed tables type with unique.
    2) subtract the result:
    loop at it_1 into ls_1.
      lv_tabix = sy-tabix.
      read table lt_1 transporting no fields with table key column_name =  ls_1-column_name.
    check sy-subrc eq 0.
      delete it_1 index lv_tabix.
    endloop.
    this solution will speed up your application.

  • MINUS operation with remote table

    Hi all,
    Please help me with this problem.
    I have two tables with 20 columns each, one table resides on one database and the other table is accesed through a db link. Both tables contains +800,000 records.
    I need to know the record differences between these two tables - this is a periodical process, not for once- , I am using a MINUS operation with full scan, the problem is that my query is taking long time to finish : +20 min. Also i tried witn COLUMN IN() instead MINUS but my query performance is worst.
    Do you know another way to get the record differences with a better performance?
    Thanks in advance
    Edited by: Osymad on Jun 18, 2012 5:12 PM

    Osymad wrote:
    Hi all,
    Please help me with this problem.
    I have two tables with 20 columns each, one table resides on one database and the other table is accesed through a db link. Both tables contains +800,000 records.
    I need to know the record differences between these two tables - this is a periodical process, not for once- , I am using a MINUS operation with full scan, the problem is that my query is taking long time to finish : +20 min. Also i tried witn COLUMN IN() instead MINUS but my query performance is worst.
    Do you know another way to get the record differences with a better performance?
    Thanks in advance
    Edited by: Osymad on Jun 18, 2012 5:12 PMhttp://www.oracle.com/technetwork/issue-archive/2005/05-jan/o15asktom-084959.html
    Search for "Comparing the Contents of Two Tables"
    Cheers,

  • Minus operator abnormal behavior question

    Oracle 10gR2/Oracle 11g on Windows 2003 R2 32-bit
    There is a very weird query with minus, it is basically:
    select id from table1 where xxxx  --> query 1
    minus
    select id from table1 where xxxx  --> query 2the queries are against the same table, only difference is the where clause. There are 3rd party implemented type and index being used in the where clause in both queries.
    query 1 returns 100 records (i.e. all the records in table1), query 2 returns 0 record.
    but with the minus operator, it returns 1 record.
    If I modify query 2, remove the 3rd party type/index, use another filter that will return 0 record too, then the minus query returns 100 records correctly.
    If I modify the whole query to use not in/not exist instead of minus, then query returns 100 records correctly.
    Question: is it possible the 3rd party type/index can cause the minus operator to behave this way?
    Edited by: modeler on Nov 18, 2009 3:15 PM
    Edited by: modeler on Nov 18, 2009 3:16 PM

    Is there any way you can put together a representative test case that we can test here?

  • MINUS operator fetches invalid record count

    Hi,
    One of the application team complained that oracle MINUS operator fetches an invalid record count after data load.
    Here are the details of the data load:
    They are using source as PROD and target as UAT.
    They are replicating the data on UAT environment in schema A from fetching the data in PROD from the same schema.
    After load when we query the count of records in UAT it shows more records in target, that is in UAT, than PROD.
    When they use MINUS operator to fetch the extra records in UAT, it shows no rows selected.
    SQL> select 'A' count(1) from A.UAT union all select 'A' count(1) from A.PROD@BISLSPD1;
    A COUNT(1)
    A.UAT 19105022
    A.PROD 19104995
    SQL> select distinct count(*) from (select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.UAT minus select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.PROD@BISLSPD1);
    COUNT(*)
    0
    SQL> select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.UAT minus select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.PROD@BISLSPD1
    no rows selected
    Please note that both are partitioned tables and they are using Informatica Data Replication 9.5 tool to populate the data from source to target.
    Not sure if this could be a bug or an issue.
    PROD DB Version: 10.2.0.5
    UAT DB Version: 10.2.0.5
    Both are in Linux 2.6
    Please throw some light on this.

    974065 wrote:
    SQL> select 'A' count(1) from A.UAT union all select 'A' count(1) from A.PROD@BISLSPD1;
    A                  COUNT(1)
    A.UAT                     19105022
    A.PROD                   19104995
    SQL> select distinct count(*) from (select distinct  DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.UAT minus select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.PROD@BISLSPD1);
    COUNT(*)
    0
    SQL> select distinct  DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.UAT minus select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.PROD@BISLSPD1
    no rows selected
    Given that you've go "distinct" in your query, you're eliminating duplicates from each table (and MINUS implicitly means distinct anyway). Check for duplicates (of dw_discount_key, dw_discount_modifier_key) in both tables.
    If the combination is actually unique, I would check that you actually had the raw results the right way round - MINUS is not symmetrical, and for a complete picture you need to look at (select from uat minus select from prod) union all (select from prod minus select from uat)
    Regards
    Jonathan Lewis

  • Error while doing MINUS operation

    Hi ,
    i am using MINUS operation.I am getting the error
    *State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 59019] All of the input streams to the Union operator should have an identical number of columns and union compatible data types. (HY000)*
    I used same data type and i checked with rpd also its working fine.Where is the problem .Can any one help me out??
    Thanks,
    Saichand.V

    hi,
    Thanks for u quick response
    Those are from two Different tables.in Fx i didn't used any operations.Just pulled certain columns.one column is prompted in both the reports.

  • How to use pre-mapping process operator

    Hi,
    I am using OWB version 10.1.0.4.0.
    There are two source tables namely src1_tb(id1,field1,field2), src2_tb(id2,field3,field4) and a target table namely target_tb(id1,id2,field1,field2,field3,field4).
    It's a simple mapping with a join operator. Here, when I try to use a pre-mapping process operator 'LENGTH', with input from outgroup of join operator (field1) and output linked to an added field( VALUE_LENGTH) in Traget Table, it gives error "VLD-2451: Connection to premapping is invalid" and a warning "VLD-1008 :Referenced mapping column VALUE_LENGTH" does not exist"
    Can anyone please let me know how to use pre-mapping process operator.
    Any help will be greatly appreciated.
    Regards,
    Pawan

    yes, a pre-mapping procedure is not what you want here.
    Pre-mapping procedures run once when the mapping initializes and before the actual ETL is run. IT is a place where you could do some custom data cleansing / validation, populate your own audit loggin tables if you wish, or whatever other things you might like to do.
    For what you are describing, you want to pass the field through an expression object. Drop the Expression on the canvas and drag a link from the field in your OUTGRP to the INGRP on the expression This will auto-create the corresponding ingrp attribute in the expression for that field. Then double-click the expression object to bring up it's properties sheet. You will then want to create an OUTGRP attribute called length_value of type number, and set it's Expression property to length(ingrp1.your_Field_name_here). You can then connect from this outgrp field to your field in the target table.
    Cheers,
    Mike

  • How do I use the "double-layer" function with my iMac?

    Hi,
    Just wondering who can help me. I want to burn a dvd using the double-layer feature. The thing is I don't know if my iMac comes with that application preinstalled. I don't even know if I need an application and which one. The only thing I have for the moment is the "LightScribe DVD+R".
    Thank you

    "Double-layer" is a property of the media (the disk itself). There are no options in software necessary to support writing to it, it just uses the second layer if the data won't fit on a single-layer and the disk in the drive has a second-layer.
    As far as software is concerned, there's no notion of "layers" on the disk. The software simply sees the disk as 4.5G (a regular DVD+R) or 9G (DVD+R DL). Handling of writing multiple layers is handled by the drive itself.
    You'll note that you can't treat single-layer discs as double-layered ones. The drive can tell what sort of disk was inserted.

  • How do I use the double sided printing with my HP Officejet 6500A plus

    I need help with learning to use the double sided printing with my HP Officejet 6500A Plus

    Click on the Show Details button just above:
    You can configure various options from the dropdown menu just below Orientation.
    Printing two-sided requires a two-sided adaptor for the printer. Otherwise, you have to print out odd numbered pages first, turn them over and reinsert into the paper feeder, then print even numbered pages. If you do it right you get a nice two-sided document. If you do it wrong all the even numbered pages will be upside down.

  • I am using your software: CS^ InDesign Suite on a PC using a Windows 7 operating system.     Due to eyesight issues, I need to have the menu bars of programs in easy-to-read font and picture size.  Specifically, the menu bar

    Hi,
    I am using your software: CS6 InDesign Suiteon a PC using a Windows 7 operating system.
    Due to eyesight issues, I need to have the menu bars of programs in easy-to-read font and picture size.  Specifically, the menu bar across the top (File, Edit, View, etc.), and the menu bar on the left side with the graphic depiction of options.
    In earlier versions of Windows (e.g. XP), whenever I changed the screen resolution on my computer to a lesser resolution in order to show the link icons on my desktop in a larger, more readable size, all the software programs, including yours, appeared on my screen with the menu bars in the larger font size that I needed.
    However, in Windows 7, this is not the case.  Even though I have selected the lowest resolution, making the icons on my desktop extremely large, I cannot read the options across the top menu bar of your program, nor the pull-down menu items that they contain.  I cannot see the graphic depictions of options on the left side of the screen. They are all too small.  How can I make your program increase the size?

    CS6 is not high-DPI compatible/ enabled and that can't be changed. If you cannot6 make it work with your operating system means, then short of joining Creative Cloud and using newer versions there is nothing you can do.
    Mylenium

Maybe you are looking for

  • How to Refer the Selected value in a Select List

    I have a page item which is a select list. I have a button in my region which when clicked will call a process. This process takes the current value of my page item as a parameter. However, when I select a value from the Select list and click on the

  • HOW COME MY PHONE WONT TEXT MY GMAIL ANYMORE

    HOW COME MY PHONE WONT TEXT MY GMAIL ANYMORE

  • Droid X accessories

    I have a Droid X and thinking about getting the Droid Bionic , my question is will the bionic fit in the car dock and the home dock ?? thank you in advance for any insight

  • LSO - impart qualification with quantity scale

    Hi experts, I have a problem here that I'd like to share with you. We are building a qualification and training catalogs for LSO, and one of the areas would like that a group of trainings summed would impart one qualification. The problem is that the

  • Replacing an AT-MIO-16X with a PCI-MIO-16XE

    Updating an old system we upgrade DAQ card with one we tough was "all" identical, but I found that the DIO port is not. In fact the MIO-16X can be define as an 4 bits port but not the new card PCI-MIO-16XE-10. Unfortunately the Vi we are using was de