by comparing the records with another table

Hello
I have the following 2 tables (test_prs & test_dep) and registers
My goal is to compare test_prs with test_dep records and return the records that are not in test_dep

Here is the table scripts
create table test_prs (id ,p_id ,r_id)
as
select 1,200566,200566 from dual
 union all
select 2,200567,200567
from dual

create table test_dep (id,de_typ,de_id,de_u_typ,de_u_id)
as
select 10,'AS',200566,'PG',200566
FROM DUAL
UNION ALL
select 11,'AS',200567,'PG',200567
FROM DUAL


insert into test_dep 
select 12,'AS',400189,'PG',400273 FROM dual union all
select 13,'AS',400273,'PG',400250 FROM dual union all
select 14,'AS',400273,'PG',400192 FROM dual union all
select 15,'AS',400273,'PG',400191 FROM dual

insert into test_prs
select 3,400273,400273 from dual
I tried the following query to meet my criteria. My output should be null, but all records
select * from 
test_prs  prs
where  exists (select 1 from test_dep de where de.de_id !=prs.p_id and de.de_u_id !=prs.p_id )
Could you please help me the same

Published by: smile on 7 March 2012 15:00

Smile says:
Thanks for the request

The query does not work with the following documents

insert into test_dep
select 16,'AS',750664,'PG',750758 FROM dual 

insert into test_prs
select 4,750758,750668 from dual

the r_id should not be put in correspondence with the columns in the test_dep table. P_id must only be put in correspondence

OK, you want to match against the de_id and the de_u_id p_id? Or a line where either p_id concordances r_id de_u_id or de_id must not be returned?

To match p_id against de_id and de_u_id, you can write the query like this:

select id, p_id, r_id from test_prs where
p_id in
(select p_id from test_prs
minus
select de_id from test_dep
minus
select de_u_id from test_dep);

Brgds
Johan

Tags: Database

Similar Questions

  • can I use: separation by a comma to compare the values with another table

    Hi ALL, I am using oracle 10g, can someone help me with this query
    WITH t AS
         (SELECT 20 ID, 'ABC,DEF,GHI' VALUE
            FROM DUAL),
         x AS
         (SELECT 20 ID, 'ABC' VALUE
            FROM DUAL
          UNION ALL
          SELECT 20, 'DEF'
            FROM DUAL
          UNION ALL
          SELECT 20, 'GHI'
            FROM DUAL)
    SELECT x.ID, x.VALUE
      FROM x, t
     WHERE x.VALUE IN (t.value);
    
    o/p required
    -------------------
    20  ABC
    20  DEF
    20 GHI
    I know I can't use t.valeur in TO would adopt. so I tried to use it in the paragraph, but it did not work.
    ''''|| Replace (T.valeur, ",", "", "') |" '

    Published by: DeepakDevarapalli on December 15, 2009 19:27

    Hello

    Here's a way to do it:

    SELECT      x.ID
    ,      x.VALUE
    FROM      x
    JOIN     t     ON      ',' || t.value || ','
              LIKE     '%,' || x.value || ',%'
    ;
    

    Extra commas are necessary to avoid the problem of 'mother is in chemotherapy,' when a single value can be one substring of another. If this is impossible (as in your case, where all values are exactly 3 characters) then you don't have them.

  • When I subtract two numbers DBL and try to compare the result with another DBL, it fails

    I found a curious problem with subtraction and compare numbers DBL in LabVIEW (8.6). Here's how it works:

    1. subtract two numbers DBL such that the result is not incorporated. (Say, 3.2 - 3.1)

    2. compare the result with a constant/control that is on the result of the subtraction (in the example, 0.1)

    3 see the output of the comparison.

    If the result of the subtraction is an integer, the Boolean result is (as expected). If the result is not complete, the comparison fails.

    (Now, if I simply compare two floating point numbers, it works, so the issue is not with the node comparison itself, but with the data that is entered to the node). Can someone understand why this happens? It's unexpected, it's a pretty serious bug.

    It is provided with all programming languages. Numbers do not have an exact binary floating-point representation. This has been discussed endlessly. Never use the equal function with floats. You can use the function in the range and force.

  • Update trigger that inserts the record in another table

    I searched the forum and the web for an example like this and I can not find a:

    A field is updated in the TABLE_A and it triggers a single record TABLE_B insert that has the old and the new value of the field.

    I write a lot of complex data warehouse SQL-based reports, but very rarely do much PL/SQL, any help would be appreciated.
    Thanks in advance.

    Hello

    You can specify that the trigger should fire only when certain columns are referenced, like this:

    create or replace trigger test_fund_trig
    before update OF FUNDING
    on table_a
    ...
    

    If you do this, the trigger will not draw on statements such as:

    UPDATE  table_a
    SET     mod_date = SYSDATE;
    

    You should always use an IF statement, as I mentioned earlier, if you do not want to follow the updates where the value of this column has not really changed.

  • Compare the Collection with the help of the Table less

    Hey there!

    my plan is to transfer an excel file and record in an apex_collection, compare the results with those that already exist in a specific table and write it in another temporary table.

    Import excel, in the collection works perfectly, but I fight with the comparation. I select the form of entries collection and using UNMIS to compare lines with those of another SELECTION that gets the lines of the existing table.

    DECLARE

    BEGIN

    INSERT INTO UPLOADED_DID_LIST_COMP (BAC_CODE, UPSC)

    (

    SELECT BAC_CODE c001

    c002 published

    From apex_collections ca

    WHERE collection_name = "UPLOADED_EXCEL."

    LESS

    SELECT

    BAC_CODE

    EDITED

    OF UPLOADED_DID_LIST upld, apex_collections c WHERE

    collection_name = "UPLOADED_EXCEL."

    AND the upld. BAC_CODE = c.C001

    AND the upld. LʼUPSC = c.C002

    );

    End;

    This does not work because of this error:

    ORA-00933: SQL command not properly ended ORA-06550

    PLS-00103: encountered the symbol "end-of-file" when awaits one of the following numbers: (begin case declare exit end exception for goto rise back loop mod null pragma select update while < ID > < a quot double)

    If it's a copy/paste of your exact code then you just need to fix it, spaces here and there. And remove the superfluous where clause. Maybe:

    BEGIN

    INSERT

    IN UPLOADED_DID_LIST_COMP

    (

    BAC_CODE, SCHOOLING

    )

    (

    C001 SELECT BAC_CODE, EDITED C002

    FROM APEX_COLLECTIONS CA

    WHERE COLLECTION_NAME = "UPLOADED_EXCEL."

    LESS

    SELECT BAC_CODE, SCHOOLING

    OF UPLOADED_DID_LIST UPLD

    );

    END;

    Good luck.

  • Compare the records from the same table

    Hi all

    I have this sample, the data were rendered are group by my_id, the same number of records exist for the two my_ids (2 and 62) as:

    create table myTest as
    (
    my_id number, 
    fieldA varchar2, 
    fieldB number, 
    fieldC number, 
    cost_A number, 
    cost_B number
    )
    
    insert into myTest (my_id, fieldA, fieldB, fieldC, cost_A, cost_B)
    values (2, 'MAINT', 60, 5, 10.3, 15.00);
    insert into myTest (my_id, fieldA, fieldB, fieldC, cost_A, cost_B)
    values (2, 'MAINT', 70, 6, 20.3, 25.00);
    insert into myTest (my_id, fieldA, fieldB, fieldC, cost_A, cost_B)
    values (2, 'MAINT', 80, 7, 30.3, 35.00);
    insert into myTest (my_id, fieldA, fieldB, fieldC, cost_A, cost_B)
    values (62, 'MAINT', 60, 5, 10.3, 5.00);
    insert into myTest (my_id, fieldA, fieldB, fieldC, cost_A, cost_B)
    values (62, 'MAINT', 70, 6, 20.3, 25.00);
    insert into myTest (my_id, fieldA, fieldB, fieldC, cost_A, cost_B)
    values (62, 'MAINT', 80, 7, 10.3, 15.00);
    

    How can display the records with numbers of different costs for the same unique key (fieldA, fieldB and FieldC)?

    With the help of Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0.

    I hope that my message is clear.

    Thank you!

    Hello

    user9542267 wrote:

    ... I need all the exits...

    Me too.  Always show the complete, accurate, results you want from the data provided.  If you want 2 rows at the exit point, don't tell you want 1.

    Here are the results you want?

    MY_ID FIELDA, FIELDB, FIELDC OLD_COST_A COST_A OLD_COST_B COST_B

    ------ ---------- ------ ------ ---------- ------ ---------- ------

    MAINT 62 60 5 10.3 10.3 15 5

    MAINT 62 80 7 30.3 10.3 35 15

    If so, here's a way to get them:

    WITH got_old_costs AS

    (

    SELECT fielda, fieldb, fieldc, cost_a, my_id, cost_b

    , LAG (cost_a) OVER (PARTITION BY fielda, fieldb, fieldc)

    ORDER BY my_id

    ) AS old_cost_a

    , LAG (cost_b) OVER (PARTITION BY fielda, fieldb, fieldc)

    ORDER BY my_id

    ) AS old_cost_b

    OF mytest

    WHERE my_id IN (2, 62)

    )

    SELECT my_id, fielda, fieldb, fieldc

    old_cost_a, cost_a

    old_cost_b, cost_b

    OF got_old_costs

    WHERE my_id = 62

    AND (cost_a <> old_cost_a)

    OR cost_b <> old_cost_b

    )

    ORDER BY fielda, fieldb, fieldc

    ;

  • How can I do a summation of a table summarizing several points once, leaving me with another table?

    Hello, I tried to find a way to do the summation of a table, the sum of 19 points at a time, leaving me with another table.  I feel like this has a simple solution, but I'm not sure how.

    Thank you.

    A time loop that contains the subset of the table can do.

    Lynn

  • By comparing the Date with timestamp without time portion

    Hello

    I have table lets say rates, it has a field called expire_date. Now, I need to display the records in this table which expires date is greater than today. Can someone tell me how to do?

    Currently, I do like this:

    Select * rate where expire_date > = (select SYSDATE from DOUBLE);

    This request is now selection of records whose timestamp is greater than the current date and time and other drops while the expire_Date is today with less time stamp.

    I need to show the records that are valid today and coming dates regardless of today

    Kind regards

    Ashish

    Select * rate where expire_date > = trunc (sysdate);

    Avoid the misuse of the double

    Kind regards

  • Throw the records with null values columns

    Hi all.

    Anyone know how to dispose of records containing null column values?

    In the target table, I have the set Null option? with "N"... then the process sqlldr load some records. I need to load all of this without the records with null column values. by result, if the field X is null then load the file.

    Kind regards.

    Published by: ASzo on 05/06/2013 12:37

    Published by: ASzo on 05/06/2013 12:38

    Published by: ASzo on 05/06/2013 12:42

    load data
    INFILE...
    in the table...
    When x! = ''
    fields completed by...
    (x ...)

  • Update of table column in this table corresponds with another table

    UPDATE of table column where this table corresponds to a column with another table of columns,
    Example:

    I need to update column in the table SIEBEL_ASSETS MATACH_FLAG = 'Yes' when less than the conditions of the
    Select a.*, SIEBEL_ASSETS a, gis_cad, c
    where upper (a.Province) = upper (c.province)
    and upper (a.TOWNSHIP_NAME_EXT) = upper (c.suburb)
    and a.Stand_ # = c.ERF_NO
    update siebel_assets a
    set    match_flag = 'yes'
    where  exists (select 1
                   from   gis_cad c
                   where  upper(a.Province) = upper(c.province)
                   and    upper(a.TOWNSHIP_NAME_EXT) = upper(c.suburb)
                   and    a.Stand_# = c.ERF_NO
                  )
    ;
    
  • You need to reset and or change my old icloud account of moms on the phone with another. When I try to reset it with the information that we know that it says "blocked account"

    You need to reset and or change my old iCloud account of moms on the phone with another. When I try to reset it with the information that we know that it says "blocked account"

    ACCOUNT SAFETY CONTACT NUMBERS

  • When I use my brush tool, it works very well unless I overlap the brush with another brush stroke.

    When I use my brush tool, it works very well unless I overlap the brush with another brush stroke. When this happens, it turns bright red. How can I fix this and put it on the default setting?

    Your brush is set to Hard Mix in the options bar.  Change this to normal and everything will be fine.

  • How to make a value in a temporary table, the match against another table...

    Hi all.

    Please is - can someone provide some guidance on how to...

    1. take a value from a temporary table, the match against another table that contains the first values 'equivalent' value.
    2. take this exchange value, call something (using the slider or the variable?) so I can add to my API to load it into ORACLE...

    Apology of this sounds confusing, I hope you know everything what I want to do...

    Manythanks...

    Steven

    and call the API

    declare
       v number;
    begin
       SELECT oracle_loc_code
          into v
       FROM SU_IEXP_LOCATIONS
          , SU_TEMPLOYEE_DETAILS
       WHERE chris_loc_code =location_id
       ;
       Hr_Assignment_Api.update_emp_asg_criteria (v);
    end;
    
  • delete all the records in a table, the speed of insertion is not change.

    I have an empty table, and I insert a record need 100ms.
    During this table a 40,0000 trace, I insert a record need 1 s, it's ok, because I need to make a comparison according to an index before inserting a record need, so more record, more time.
    The problem is when I delete all the record in this table, the insertion time is always 1s, not reduce to 100ms. Why?

    Hello

    Read this part of the oracle documentation

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14220/logical.htm#CNCPT004

    The reason is always 1s, because when you inserted 400ko record as HWM (high tide is the border between old and new space in a segment.) moved to the top. And when you remove all records of your HWM still in the same coordinate system and that you have not reset to 0. So when you insert 1 it save free space and after finding faces (usually a regular insertions got 6 steps it inserts data). If you truncate your table you and try it again it will be faster that your HWM is reset to 0.

    Concerning

  • Insert the record of one table to another with the help of the cursor

    Help, please!

    the tables are - 1. countries (country_id pk, country_name, region_id)
    2A (country_id, country_name, region_id)
    table data are
    1 to 1
    2 b 2
    3 C 3
    NULL d 4
    5 e 5
    6 f 6
    7 g 7
    -----------------------
    Insert the record in the table a country table with the help of the cursor, insert all the non-null records.
    This procedure does not correct result
    -----------------------

    create or replace
    Amit procedure as
    cursor c1 is select * from a;
    RW a % rowtype;
    Start
    Open c1;
    Fetch c1 into rw.
    While (C1% found)
    loop
    insert into countries values (rw.country_id, rw.country_name, rw.region_id);
    commit;
    Fetch c1 into rw.
    If rw.country_id is null then
    Fetch c1 into rw.
    end if;
    end loop;
    Close c1;
    exception
    while others then
    dbms_output.put_line ('exception = name ' |) RW.country_name);
    end;

    You don't need cursor at all;

    create or replace procedure amit as
    
    begin
      insert into countries (Country_ID, Country_Name, Region_ID)
      (select a.Country_ID
             ,a.Country_Name
             ,a.Region_ID
       from a
      );
    
      dbms_output.put_line('Rows inserted : ' || sql%rowcount);
    
      commit;
    
    end;
    /
    

Maybe you are looking for

  • Siri on iPad 2 Air after updating IOS 10

    Hello on my Ipad 2 Air after upgrade IOS 10.0.1 I have no option to change the voice of Siri in the male. The voice is that of the IOS 9.3.5. I did a complete reset, but nothing has changed. Is this normal?

  • Satellite Pro M30-701: TouchPad does not work after installation of XP Pro

    My touchPad does not work after reinstalling XP Pro OS with recovery disk. I install a driver for Toshiba M30 - 701 Synaptics TouchPad tpdrv-sp-m30-xp - 7920.zip Can you help me solve the my problem please?Excuse my bad English...Thank youJorge Neto

  • memory virtual insufficient messages

    I continue to receive virtual memory messages almost every day and sometimes I was not on this long. Does anyone know how can I fix?

  • I have the motherboard A780L3B have a question about power

    I have the A780L3B and the guid of the quick instalation shows two power connectors pin 4 and PIN 24 my question is can I plug my sorce of power in two of them, or only the instalation guid doesn't even say just said what it is and doesn't say if I n

  • Errors when creating FOD demo scripts

    I followed the steps of creation of oracle 11g scheme as written in http://www.oracle.com/technetwork/testcontent/connection11g-088156.html#t1s1:I got these errors:BuildFile: F:\programs\sql_oracle11g\sql\sql_oracle11_reference\Fusion_order_demo\Fusi