Delete based on the first column or column second row

Dear members,

Need to remove a MasterTable lines based on the value in an another RefTable (which is a subset of the main table) colA or ColB.

/ * Value refTable wedges designed to be
create table RefTable (int num1, num2 int, int temp)

Insert in the values of numbers (44445, 44444 11111)
Insert in the values of numbers (44446, 44444 11111)
Insert in the values of numbers (44447, 44444 11111)

Insert in the values of numbers (55555, 55551, 11111)
Insert in the values of numbers (55555, 55552, 11111)
Insert in the values of numbers (55555, 55553, 11111)

Insert in the values of numbers (22222, 22222 11111)
Insert in the values of numbers (22222, 22222 11111)

Suppose that MasterTable has given below
create table MasterTable (int num1, num2 int, int temp)
Insert in the values of numbers (22222, 22222 11111)
Insert in the values of numbers (22222, 22222 11111)
Insert in the values of numbers (22222, 22222 11111)

Insert in the values of numbers (44444, 44444 11111)
Insert in the values of numbers (44445, 44444 11111)
Insert in the values of numbers (44446, 44444 11111)
Insert in the values of numbers (44447, 44444 11111)

Insert in the values of numbers (55555, 55551, 11111)
Insert in the values of numbers (55555, 55552, 11111)
Insert in the values of numbers (55555, 55553, 11111)
Insert in the values of numbers (55555, 55554, 11111)

insert into numbers values (4567, 12345, 11111)
insert into numbers values (5678, 23456, 11111)

The query should execute delete on MasterTable RefTable value-based to get the result that

4567 11111-12345-
5678 23456-11111.

I tried to change the query something like
delete of the MasterTable where num1 = any (select num1 of RefTable); but it can only manage the deletion of the colA part... Any suggestions
Is this ?

DELETE
FROM
     MasterTable mt
WHERE
     EXISTS
     (
          SELECT
               1
          FROM
               RefTable rt
          WHERE
               rt.num1 = mt.num1
                 OR
                        rt.num2 = mt.num2
     )
 

Tags: Database

Similar Questions

  • How better to insert a subarray (line) in a 2D array to the correct index which is based on the value of the first column

    Hello

    I would like to insert a subarray (line) in a 2D to the correct index table. The position is to say the index value depends on the value of the first column of the table 2d.

    As an examlple my 2d array would look like this

    230 50 215 255

    300 60 270 330

    360 20 350 370

    And I would like to insert another line (subarray) with the following values

    320 40 300 340

    This new line should be placed between the second and third rows (this is based on the first column only).

    I tried the threshold 1 d function table by taking an 1Dsub array of my 2d array (first column), then using the first of the new line (320) as the threshold. It sort of work, but it does not work when I start the table (IE there is only 1 row) and it seems to not work properly on other occasions (as explained in the help of Labview).

    Hopefully the explanation is clear enough for any suggestion. Thanks in advance for the help!

    JTRI wrote:

    The idea is I have start with a new table and add these lines in the right order every time that the user sets the values Jack

    Ahh, so try this.

    This will also work with an empty array.

    You want to do with this function it is a Subvi.

    Make the entries 'table' and 'subarray"on the connector, then 'new array' output.

    You can then put this Subvi in a loop with a registry to shift and it will help to add new lines in a sorted order, when they are added.

    That is what you were aiming for?

  • How remove the line by line by comparing to the first column?

    Hello!

    I have a problem - I need to remove the line by line, but the problem is, I know that the first COLUMN of the table is a PK.
    To retrieve the NAME of the COLUMN that I use:

    SELECT column_name, table_name FROM USER_TAB_COLUMNS WHERE column_id = 1 and table_name = c1.tmp_table_name;
    But it does not somehow.
    Below you can see my script (which has not worked for now):

    declare
    XXX varchar2 (100);
    Start
    C1 in (select table_name, tmp_tables tmp_table_name) loop
    IMMEDIATE EXECUTION
    ' SELECT column_name in ' | xxx | "USER_TAB_COLUMNS WHERE column_id = 1 AND table_name = ' |" ' || C1.tmp_table_name | " ' ;
    immediate execution
    "start."
    for c2 in (select * from ' | c1.tmp_table_name | start loop ')
    Insert into ' | C1.table_name | "values c2; delete from ' | C1.tmp_table_name | 'where ' | xxx |' = c2.' | xxx |'; exception: when other then null; end; end loop; end;';
    end loop;
    end;

    P.S. The Inserts work perfect. I have a problem with deleting lines that are in c1.table_name, of c1.tmp_table_name (the two tables have the same structure, PK, always), because I have the names of columns different another tables which are PK. (for example: K, ID, NS and so on) Please help me to write the correct script.
    For example this will be for the first line recovered as:
    Start
    C1 in (select table_name, tmp_tables tmp_table_name) loop
    immediate execution
    «Start for c2 in (select * from ' |)» C1.tmp_table_name | Start loop ')
    Insert into ' | C1.table_name | "values c2; delete from ' | C1.tmp_table_name: ' where K = c2. K; exception: when other then null; end; end loop; end;';
    end loop;
    end;
    This script works perfectly. But I have many other tables with different PK - K No.

    Solution with the logging of errors table

    -- create the error-logging table
    CREATE TABLE tbl_MergeErrors (
        Stamp       TIMESTAMP(3),
        TableName   VARCHAR2(30),
        KeyColumn   VARCHAR2(30),
        KeyValue    VARCHAR2(4000),
        ErrorCode   NUMBER(5),
        ErrorMsg    VARCHAR2(4000),
    
      CONSTRAINT pk_MergeErrors
          PRIMARY KEY (TableName, Stamp)
          USING INDEX
    )
    /
    
    -- procedure to insert errors
    CREATE OR REPLACE
    PROCEDURE LogMergeError (pTableName  IN VARCHAR2,
                             pKeyColumn  IN VARCHAR2,
                             pKeyValue   IN VARCHAR2)
    IS PRAGMA AUTONOMOUS_TRANSACTION;
    
        -- you couldn't insert SQLCODE or SQLERRM directly into a table (ORA-00984)
        nSQLCODE   NUMBER(5)      := SQLCODE;
        vcSQLERRM  VARCHAR2(4000) := SQLERRM;
    
    BEGIN
      INSERT INTO tbl_MergeErrors
             (Stamp, TableName, KeyColumn, KeyValue, ErrorCode, ErrorMsg)
          VALUES (SYSTIMESTAMP, RTrim( SubStr( pTableName, 1, 30)),
                  RTrim( SubStr( pKeyColumn, 1, 30)), SubStr( pKeyValue, 1, 4000),
                  nSQLCODE, vcSQLERRM);
      COMMIT WORK;
    
    -- if an error occured here, then just roll back the autonomous transaction
    EXCEPTION
      WHEN OTHERS THEN   ROLLBACK WORK;
    END LogMergeError;
    /
    
    -- create the tables and insert test-data
    CREATE TABLE TMP_TABLES (
        TABLE_NAME       VARCHAR2(200),
        TMP_TABLE_NAME   VARCHAR2(200),
      CONSTRAINT TMP_TABLES_X PRIMARY KEY (TABLE_NAME)
    )
    /
    CREATE TABLE TMP_KL002 (
        K   VARCHAR2(40),
        N   VARCHAR2(200)
    )
    /
    CREATE TABLE TMP_TABLE1 (
        NS   VARCHAR2(40),
        N    VARCHAR2(200)
    )
    /
    CREATE TABLE KL002 (
        K VARCHAR2(40),
        N VARCHAR2(200),
      CONSTRAINT PK_KL002 PRIMARY KEY (K)
    )
    /
    CREATE TABLE TABLE1 (
        NS   VARCHAR2(40),
        N    VARCHAR2(200),
      CONSTRAINT PK_TABLE1 PRIMARY KEY (NS)
    )
    / 
    
    INSERT INTO TMP_TABLES (TABLE_NAME, TMP_TABLE_NAME) VALUES ('kl002','tmp_kl002');
    INSERT INTO TMP_TABLES (TABLE_NAME, TMP_TABLE_NAME) VALUES ('table1','tmp_table1');
    INSERT INTO tmp_KL002 (K, N) VALUES ('00', 'none');
    INSERT INTO tmp_KL002 (K, N) VALUES ('07', 'exists');
    INSERT INTO tmp_KL002 (K, N) VALUES ('08', 'not assigned');
    INSERT INTO tmp_table1 (NS, N) VALUES ('2000', 'basic');
    INSERT INTO tmp_table1 (NS, N) VALUES ('3000', 'advanced');
    INSERT INTO tmp_table1 (NS, N) VALUES ('4000', 'custom');
    COMMIT WORK;
    
    -- to test, if it works correct when primary key values exists before
    INSERT INTO KL002 VALUES ('07', 'exists before');
    COMMIT WORK;
    
    -- check the data before execution
    SELECT * FROM TMP_KL002 ORDER BY K;
    SELECT * FROM KL002 ORDER BY K;
    SELECT * FROM TMP_TABLE1 ORDER BY NS;
    SELECT * FROM TABLE1 ORDER BY NS;
    
    -- empty the error-logging table
    TRUNCATE TABLE tbl_MergeErrors DROP STORAGE; 
    
    -- a solution
    DECLARE
    
        PLSQL_BLOCK  CONSTANT VARCHAR2(256) := '
    BEGIN
      FOR rec IN (SELECT * FROM <0>) LOOP
        BEGIN
          INSERT INTO <1> VALUES rec;
          DELETE FROM <0> t WHERE (t.<2> = rec.<2>);
        EXCEPTION
          WHEN OTHERS THEN
              LogMergeError( ''<1>'', ''<2>'', rec.<2>);
        END;
      END LOOP;
    END;';
    
    BEGIN
      FOR tabcol IN (SELECT t.Tmp_Table_Name, t.Table_Name, c.Column_Name
                     FROM Tmp_Tables t,
                          User_Tab_Columns c
                     WHERE     (c.Table_Name = Upper( t.Tmp_Table_Name))
                           AND (c.Column_ID = 1)
                ) LOOP
        EXECUTE IMMEDIATE Replace( Replace( Replace( PLSQL_BLOCK,
                                   '<0>', tabcol.Tmp_Table_Name),
                                   '<1>', tabcol.Table_Name),
                                   '<2>', tabcol.Column_Name);
      END LOOP;
    END;
    / 
    
    -- check the data after execution ...
    SELECT * FROM TMP_KL002 ORDER BY K;
    SELECT * FROM KL002 ORDER BY K;
    SELECT * FROM TMP_TABLE1 ORDER BY NS;
    SELECT * FROM TABLE1 ORDER BY NS;
    
    -- ... and also the error-logging table
    SELECT * FROM tbl_MergeErrors ORDER BY Stamp, TableName;
    
    -- of couse you must issue an COMMIT (the ROLLBACK is only for testing
    ROLLBACK WORK;
    
    -- drop the test-tables
    DROP TABLE TABLE1 PURGE;
    DROP TABLE KL002 PURGE;
    DROP TABLE TMP_TABLE1 PURGE;
    DROP TABLE TMP_KL002 PURGE;
    DROP TABLE TMP_TABLES PURGE;
    
    -- you shouldn't drop the error-logging table, but I use it to free up my db
    DROP TABLE tbl_MergeErrors PURGE;
    

    Greetings, Niels

  • Read the data in the first column selected in a multicolumn listbox

    When a line is selected in a ListBox multicolumn (1 point), how can I go on reading the data in the first column?

    The listbox multicolumn itself is the digital picture data type. If you have allowed only 1 point selection and selection mode select any row, it returns the line number. The property node 'Element names' to return a table 2d-chains of the elements in your Inbox. The index of the row to the value of the listbox and column 0. See code attached.

  • adding multiple files *.csv while retaining the original file name in the first column

    Hi guys Cela made some time.

    I am trying to add several *.csv files while retaining the original file name in the first column, the real data set is about 40 cases.

    file a.csv contains:
    1, line an a.csv
    2, line 2 in a.csv

    file b.csv contains:
    1, line a b.csv
    2, line 2 in b.csv

    result output.csv is:

    I would like this:
    a.csv, 1, the line in a.csv
    a.csv, 2, line 2 in a.csv
    b.csv, 1, the line in b.csv
    b.csv, 2, line 2 in b.csv

    Any suggestions to speed up my hobbling attempts would be aprieciated

    Thank you

    -SS

    What you could do is given in attachment.

    Started with 2 files:

    a.csv

    copy of a.csv

    Both with data:

  • Photosmart Premium C309a print only the first column of the Excel worksheet

    Photosmart Premium C309a print only the first column of the Excel worksheet

    Hello

    I see you are having a problem printing to an Excel document.

    I suggest you install a default substitution such as the jet pilot desktop 990 c driver.

    You can follow this thread of Shane, who will show you how.

    After that, you can try printing again from Excel.

  • Columns of folder: by default, how can return the first column 'Name' without having to move it manually every time?

    Something's happened awhile and when I create a folder which appears the first column is the column 'Date modified '. By default, how can return the first column 'Name' without having to move it manually every time?

    Hello

    I suggest you to visit these links and check if it helps:

    http://Windows.Microsoft.com/en-us/Windows-Vista/working-with-files-and-folders#section_4

    http://Windows.Microsoft.com/en-us/Windows-Vista/folders-frequently-asked-questions

    It will be useful.

  • How the first column heading must be repeated if the table breaks across pages

    Hi Experts,

    RTF model, header row in the table automatically repeat if record go to the next page. in similar fasion, I want to repeat the first column heading, table breaks on any page.

    Please help reslove this issue...

    Hello

    You can add the tag to the first column and the first row of the table. It will repeat 1st column when table to break across pages.

    Here 1 means, repeat first column when table to break across pages.

    I hope this will solve your problem.

    P.S. If you provide 2, this means, repeat for column 2 of the table through the pages

    Please check the issue as resolved, if that answers your question. Thank you

  • How to count the first column automatically.

    Dear all.

    I would like to calculate the first column from 1 to N, when the user clicks on the add a line button.

    Please refer to the following

    -------------------------------------- Code --------------------------------------

    var nNodes is Test_Result1.sub_Product_accessories. Config_Acc.resolveNodes ("Config_Acc [*]"). Length;


    If (nNodes < = 6) {}
    Test_Result1.sub_Product_accessories. Config_Acc.instanceManager.addInstance ();
    }

    AS-IS

    count.JPG

    AS IT WILL BE

    count2.JPG

    Javascript code the Initialize event of the AccNum field:

    this.rawValue = this.parent.index + 1

  • Change the first column seen in the datagrid by code?

    Hello

    Is anyway to change the first column in a DataGrid using action script? I mean, for example, think I have 10 columns, only 3 are seen (0,1,2). I just want to have a button to change the first column view. Thus, for example, if I press it, 1.2, and third column will be those that is displayed in the datagrid control. I need to emulate the same thing that the scroll bar when you drag in a datagrid, but instead of letting the scroll bar does that automatically, I want to "scroll" datagrid manually.

    Moreover, is anyway through datagrid children and hide the scrollbar manually?

    Thanks in advance,

    Aron.

    horizontalScrollPolicy

  • Rows based on the timestamp column

    Hi Experts

    I'm trying to get the last 3 records based on the timestamp column. But I am not able to understand where I should start... ?

    To make it more clear

    I have the following data
    id date
    1  07/03/09 3:57:55.000000 PM
    2  08/03/09 9:23:55.000000 PM
    3  05/03/09 7:53:55.000000 PM
    4  08/03/09 5:41:55.000000 PM
    5  06/03/09 8:50:55.000000 PM
    I want to
    2  08/03/09 9:23:55.000000 PM
    4  08/03/09 5:41:55.000000 PM
    1  07/03/09 3:57:55.000000 PM
    Thanks and greetings
    Saurabh Sharma
    select *
      from (
    select *
      from x
     order by dt desc
     )
      where rownum <= 3
    

    Published by: Alex Nuijten on March 10, 2009 11:31

  • checkbox in the first column of the reports

    Hi all
    I have a classic report where the first column is checkbox display.
    Instead of the box, can I have the radio button.
    If it is not possible,
    When a check box is selected, the others should not get selected.


    Please guide me to get it used.

    Thanks in advance
    Good bye
    Sonny_starck

    Hello Sonny_starck,

    Yes you can. Try this:

    SELECT APEX_ITEM.RADIOGROUP (1,deptno,'20',dname) dt, deptno, dname
    FROM   dept
    ORDER  BY 1
    

    Kind regards
    Roel

    http://roelhartman.blogspot.com/
    http://www.bloggingaboutoracle.org/
    http://www.Logica.com/

  • Limit the number of characters in a text based on the first digit field

    Hello and thank you in advance for your help!

    I want to limit the amount of characters in the text field based on the first digit of the number (the text field is limited to a number format... no decimals, no comma).

    For example, if the number starts with a 3, I would limit the text field to allow only ten characters. I have three scenarios but if I could start with code and what is the best place to add (key combination or validation?) I can take it from there. Thanks again for your help!

    I wrote this code for you that does this. Use it as a typo of the custom field code:

    // Validate that only digits are entered
    if (event.change) {
        event.rc = /^\d+$/.test(event.change);
    }
    
    // Validate string length if it starts with 3
    if (/^3/.test(AFMergeChange(event))) {
        event.rc = AFMergeChange(event).length <= 10;
        if (!event.rc) app.alert("If the number starts with \"3\" it may not be longer than 10 digits.",1); // optional error message
    }
    

    You can duplicate the second part of it for additional terms, but keep in mind that this code won't let you even remove the first character in the field if the result is not valid.

    For example, if you enter "234567890123456" then you can't remove the "2" at the beginning because that would result in a number not valid. You can delete all the other numbers, even if and when it is 10 digits or less, then you can remove the departure "2" as well.

  • after delete the classified, the cursor will move to the first column

    Hi all

    After that I selected the lov and click the clear button, it erases that filed and went to the 1st column, for that I clearly want the column & stay with this column only, how to put in shape?

    Thank you



    Hi, sorry for this, put the code is the "back" button. When you press the button Search, that he will go to the block of data you press back button to find the right block. So, can you please put GO_ITEM(:global.goitem); this code button at the rear of the block of data

  • How to compare one by an element of a column with the first column in the other table?

    Hello

    I have two files into a single file has only Id numbers and the second file has table with for example the column 4, and his first column identification number.

    So I want to compare the first item in the User.ID file with the 1st column all the table file items in this column until it finds matches.

    If compare match then LED will be IT other wise LED will be OFF.

    Here as an attachment, I've attached the two file.

    Please guide me how can I do the same thing.

    Thank you much in advance.


Maybe you are looking for