matching rows

Hi all

CREATE TABLE NUM2 (NUM1, NUM2 NUMBER);

INSERT IN NUM2 VALUES (1,1)

INSERT IN NUM2 VALUES (1,2)

INSERT IN NUM2 VALUES (2,1)

INSERT IN NUM2 VALUES (2,2)

INSERT IN NUM2 VALUES (3,1)

INSERT IN NUM2 VALUES (3.2)

INSERT IN NUM2 VALUES (3,3)

INSERT IN NUM2 VALUES (4.1)

INSERT IN NUM2 VALUES (4.2)

SELECT * FROM NUM2

I want to output to match the columns as

NUM1 NUM2

1 1

2 2

7 ·

Thank you

SQL > select *.
2 of num2
3 where num1 = num2
4.

NUM1 NUM2
---------- ----------
1          1
2          2
3          3

SQL >

SY.

Tags: Database

Similar Questions

  • There is no sql to find no matching rows

    Hi all

    I want to optimize the sql where I find the column (junction of two columns) presents in a table (tab1) but not in other (tab2). I tried something like that, but it is showing me no line.

    SELECT COL1 | COL2

    OF e TAB1

    where there is NO

    (

    Select 1 in TAB2 rd

    Join e TAB1 on e.COL1 | e.COL2 = RD. COL1 | RD. COL2

    )

    When I use the simple sql (which takes a lot of time hell) I get good output: 0

    SELECT COL1 | COL2

    OF e TAB1

    where COL1 | Col2 not in

    (

    Select COL1 | Col2 from TAB2 rd

    )

    What is wrong in the query "EXISTS NOT", or suggest me best way to achieve the same thing. Thank you!

    Few things

    1. do not concatenate columns, and then compare. They can cause an incorrect result. Consider this

    tab1.col1 = 'KAR' and tab1.col2 = 'THICK'
    
    and
    
    tab2.col1 = 'KARTHI' and tab2.col2 = 'CK'
    

    Concatenation and join them will result in the return line. But in fact they do not condition.

    2. NO EXISTS and NOT IN are not the same. The two manage NULL value very differently. If there is a NULL value in the sub operator NOT IN the entire State query fails.

    https://asktom.Oracle.com/pls/asktom/f?p=100:11:0:no:P11_QUESTION_ID:442029737684

    Says, try something like this

    select t1.*
      from tab1 t1
    where not exists
           (
               select null
                  from tab2 t2
                 where t1.col1 = t2.col1
                   and t1.col2 = t2.col2
           )
    
  • Matching records between 2 tables with duplicate records

    Hi all

    I need help in what follows.

    I have 2 tables Received_bills and Send_bills.

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

    -The DOF for Table SEND_BILLS

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

    CREATE TABLE SEND_BILLS

    (DATE OF "DATUM",

    NUMBER OF "PAYMENT."

    'CODE' VARCHAR2 (5 BYTE)

    )  ;

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

    -The DOF for Table RECEIVED_BILLS

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

    CREATE TABLE 'RECEIVED_BILLS '.

    (DATE OF "DATUM",

    NUMBER OF "PAYMENT."

    'CODE' VARCHAR2 (5 BYTE),

    VARCHAR2 (5 BYTE) 'STATUS' )  ;

    INSERTION of REM in RECEIVED_BILLS

    TOGETHER TO DEFINE

    Insert. RECEIVED_BILLS (DATUM, PAYMENT, CODE, STATE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'SUCCESS');

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 'A5', 'SUCCESS', 25);

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4', 'FAILED');

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'FAILED');

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'SUCCESS');

    INSERTION of REM in SEND_BILLS

    TOGETHER TO DEFINE

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('09-OCT-15','DD-MON-RR'), 19, 'A8');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 20, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');

    I match all records of send_bills and received_bills with a status of 'SUCCESS' There is no single column in the table.

    Correspondence held payment of columns, the code and the scratch cards, but it may also duplicate records. But even if there are duplicates, I also need those records in the query results

    the query I wrote is this:

    SELECT SEND.*

    REC received_bills, send_bills send

    WHERE send.datum = rec.datum

    AND send.payment = rec.payment

    AND send.code = rec.code

    AND 'rec.status =' SUCCESS

    ;

    The query results give me this

    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1525A5
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1525A5

    The result of the correct application would be

    OCTOBER 10, 1519A1
    OCTOBER 10, 1525A5
    OCTOBER 10, 1519A1

    The select statement that I need I want to use a loop to insert records in another table.

    Can someone help me please?

    Thanks in advance.

    Best regards

    Caroline

    Hi, Caroline.

    Caroline wrote:

    Hi all

    I need help in what follows.

    I have 2 tables Received_bills and Send_bills.

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

    -The DOF for Table SEND_BILLS

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

    CREATE TABLE SEND_BILLS

    (DATE OF "DATUM",

    NUMBER OF "PAYMENT."

    'CODE' VARCHAR2 (5 BYTE)

    )  ;

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

    -The DOF for Table RECEIVED_BILLS

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

    CREATE TABLE 'RECEIVED_BILLS '.

    (DATE OF "DATUM",

    NUMBER OF "PAYMENT."

    'CODE' VARCHAR2 (5 BYTE),

    VARCHAR2 (5 BYTE) 'STATUS');

    INSERTION of REM in RECEIVED_BILLS

    TOGETHER TO DEFINE

    Insert. RECEIVED_BILLS (DATUM, PAYMENT, CODE, STATE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'SUCCESS');

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 'A5', 'SUCCESS', 25);

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4', 'FAILED');

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'FAILED');

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'SUCCESS');

    INSERTION of REM in SEND_BILLS

    TOGETHER TO DEFINE

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('09-OCT-15','DD-MON-RR'), 19, 'A8');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 20, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');

    I match all records of send_bills and received_bills with a status of 'SUCCESS' There is no single column in the table.

    Correspondence held payment of columns, the code and the scratch cards, but it may also duplicate records. But even if there are duplicates, I also need those records in the query results

    the query I wrote is this:

    SELECT SEND.*

    REC received_bills, send_bills send

    WHERE send.datum = rec.datum

    AND send.payment = rec.payment

    AND send.code = rec.code

    AND 'rec.status =' SUCCESS

    ;

    The query results give me this

    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 25 A5
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 25 A5

    The result of the correct application would be

    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 25 A5
    OCTOBER 10, 15 19 A1

    The select statement that I need I want to use a loop to insert records in another table.

    Can someone help me please?

    Thanks in advance.

    Best regards

    Caroline

    Want to get answers that work?  Then make sure that the CREATE TABLE and INSERT statements you post too much work.  Test (and, if necessary, correct) your statements before committing.  You have a stray "." in the first INSERT statement for received_bills and receikved_bills.status is defined as VARCHAR2 (5), but all values are 6 characters long.

    There are 5 lines in send_bills that are similar to the

    10 OCTOBER 2015 19 A1

    Why do you want that 2 rows like this in the output, not 1 or 3, or 4 or 5?  Is it because there are 2 matching rows in received_bills?  If so, you can do something like this:

    WITH rec AS

    (

    SELECT the reference, payment, code

    , ROW_NUMBER () OVER (PARTITION BY datum, payment, code)

    ORDER BY NULL

    ) AS r_num

    OF received_bills

    Situation WHERE = 'SUCCESS'

    )

    send AS

    (

    SELECT the reference, payment, code

    , ROW_NUMBER () OVER (PARTITION BY datum, payment, code)

    ORDER BY NULL

    ) AS r_num

    OF send_bills

    )

    SELECT send.datum, send.payment, send.code

    REC, send

    WHERE send.datum = rec.datum

    AND send.payment = rec.payment

    AND send.code = rec.code

    AND send.r_num = rec.r_num

    ;

    Note that the main request is very similar to the query you posted, but the last condition has changed.

    If you need to insert these lines in another table, you can use this query in an INSERT statement. There is no need of a loop, or for any PL/SQL.

  • I need avg for each lines dept of sage, matched and unmatched wage table

    Hi gurus,
    I doubt in sql, the employee table and department table two tables are there.

    1. I need pay for avg to each dept wise.

    2. matched and unmatched in the rows of the table

    in a request format

    Thanks and greetings
    k.Raghavan

    945795 wrote:
    Hi gurus,
    I doubt in sql, the employee table and department table two tables are there.

    Personally, it looks more like a HOME and WORK, only a DOUBT! What are your efforts on your bottom of DOUBTS?

    1. I need pay for avg to each dept wise.

    select department_id, avg(salary)
      from hr.employees
     group by department_id;
    

    2. matched and unmatched in the rows of the table

    The number of matching rows:

    select employee_id, department_name
      from hr.employees natural join hr.departments;
    

    Unpaired lines:

    select department_id, department_name
      from hr.departments d
     where not exists (
                    select 'x'
                      from hr.employees e
                     where d.department_id = e.department_id
                  )
    
  • NVL with multiple row subqueries

    Hi SQL gurus,

    I'm trying to create a MDX query for two tables with a 1 relationship: n. Bericht (b_id is the primary key) is 1 and ueber_produkt (b_id is the foreign key) is n.

    the query should return all rows in report in case: P15_PROD is null and that all matching rows in the other case.

    so far, it looks like this:

    This attempt returns a good result, but in case: P15_PROD is null, this query returns only b_id leave report which are equal to s b_id in ueber_produkt, but I would like to return all the bericht b_id. ->

    Select b.b_id, b.m_id, b.text, b.zeitaufwand, b.datum, b.kw_id
    report b
    where b.b_id in (select distinct b_id from ueber_produkt where produktname in nvl (: P15_PROD, produktname))


    It returns error "ORA-01427: einreihig subquery returns more rows"->

    Select b.b_id, b.m_id, b.text, b.zeitaufwand, b.datum, b.kw_id
    report b
    where b.b_id in nvl ((select distinct b_id d'ueber_produkt où produktname en: P15_PROD), b.b_id)

    What is a single-line subquery? I use BOF IN exploiting several subqueries in line!


    I hope I explained it well.

    Any help would be appreciated

    Hello

    oraman wrote:
    ... it returns error "ORA-01427: einreihig subquery returns more than one line"-->

    Select b.b_id, b.m_id, b.text, b.zeitaufwand, b.datum, b.kw_id
    report b
    where b.b_id in nvl ((select distinct b_id d'ueber_produkt où produktname en: P15_PROD), b.b_id)

    What is a single-line subquery? I use BOF IN exploiting several subqueries in line!

    Each of the NVL arguments must be a scalar value (that is, a single value). By putting the subquery in the NVL call, ask for it to be a scalar subquery.
    You can get the desired results by putting NVL in the subquery, like this:

    select  b.b_id, b.m_id, b.text, b.zeitaufwand, b.datum, b.kw_id
    from        bericht   b
    where      b.b_id        in (
                     select  b_id     -- DISTINCT is not needed
                     from    ueber_produkt
                     where   produktname   = NVL (:P15_PROD, b.b_id)
                   )
    ;
    

    But it might be simpler and more effective to do this:

    select  b.b_id, b.m_id, b.text, b.zeitaufwand, b.datum, b.kw_id
    from        bericht   b
    where     :p15_prod    IS NULL
    or      b.b_id        in (
                     select  b_id
                     from    ueber_produkt
                     where   produktname   = :P15_PROD
                   )
    ;
    

    Is it exactly how you think that requirements?

    the query should return all rows in report in case: P15_PROD is null and that all matching rows in the other case.

    I hope I explained it well.

    Even the best explanation leaves something to be desired. It really helps if post you a small example of data (CREATE TABLE and INSERT statements), a pair of values: p15_prod and the desired results of the same sample data for each of these values.

  • You can assign a numeric value to text

    I have a file with 8 names on it, 2 or 3 different names per day. At the bottom of the sheet, I want to show a total for each person how much time they came in a month.

    Is there a way to count these names and having a total individual for each?

    Here's a way to do this:

    In the table where you have the names (I named the table "List of names")

    Add a new column called 'Identification' as shown.

    Make the first line of header

    Select cell B2 and type (or copy and paste it here) the formula:

    = IF (COUNTIF ($A$ 2: A2, A2) = 1, MAX ($B$ 1: B1) + 1, "")

    shortcut for this is:

    B2 = IF (COUNTIF ($A$ 2: A2, A2) = 1, MAX ($B$ 1: B1) + 1, "")

    Select cell B2, copy

    Select the cells B2 at the end of column B, paste

    Now create a second table:

    I named the second table "summary of name.

    make the first line of header

    A2 = SIERREUR (OFFSET (name List: $A$ 2, MATCH ((ROW () −1), name List::B, 0)-2, 0), "")

    B2 = if (A2≠"", COUNTIF (name List::A, A2), ' ')

    Select cells A2 to B2, copy

    Select cells A2 at the end of column B, paste

  • Copy the cell values if the criteria are met, without spaces

    I wish I had a kind of summary sheet which lists all values from another sheet if they match a condition. But I want them to put on the 'Summary' sheet without a bunch of empty spaces.

    For example.   So happy = 5, put 'Food' on the summary sheet.

    It is an arbitrary example

    Name Food Happy
    Harry Apples 5
    David Candy 3
    Lola Tacos 5
    Danny Chips 2
    Suzie Steak 4
    Mark dirt 1
    Mike Sushi 5

    I want something like that

    Food .....

    Apples

    Tacos
    Sushi

    NOT

    Food ....
    Apples
    Tacos
    Sushi

    You can do this by building a column that is incremented index (which can be hidden) and then by doing a search on this index, something like this:

    The formula in D2, filled to the bottom, is:

    = IF ("C2 <>5," ", MAX(D$1:D1) + 1")

    The formula in A2 of the table summary, filled to the bottom, is:

    = INDEX(Data::B,MATCH(ROW()−1,Data::D,0)))

    SG

  • find and with an average of several lines

    Hello

    I'm having a little problem and I was wondering if anyone had any ideas on how to solve it better.

    Here's the problem:

    -J' have a 6000 lines large file by columns of 2500.

    -Firstly I sort the file by columns 1 and 2

    -then I find that different in these two columns (1 and 2) lines have the values duplicated, sometimes only twice, but sometimes three or four or five or up to 9 times.

    -This duplication occurs in only the first two columns, but we do not know where lines and we do not know how it is. The remaining columns, i.e. 3 column to column 2500, for matching rows contain data.

    -By programming, I would find the line duplicated by searching for columns 1 and 2 and when I find them, these lines of columns 3 to 2500 average data.

    -Then, once this is done I want to save average data to the file. In each line of this file must have the name of colunm 1 and 2 and the values of the row average columns 3 to 2500. So the file has n rows, columns of 2500, where n will depend on how many duplicate rows exist in the original file.

    I hope that makes sense. I explained the problem in a simple example below:

    In the example below, we have two duplicates duplicate rows 1 and 2 and four in the 5 to 8 lines.

    Example input file:

    Col1 Col2 Col3... Col2500

    3 4 0.2... 0.5

    3 4 0.4... 0.8

    8 5 0.1... 0.4

    7 9 0.7... 0.9

    2 8 0.1... 0.5

    2 8 0.5... 0.8

    2 8 0.3... 0.2

    2 8 0.6... 0.7

    6 9 0.9... 0.1

    ...

    So based on the example above, the first two lines need on average (two duplicates) as do the lines 5-8 (four in doubles). The output file should look like this:

    Col1 Col2 Col3... Col2500

    3 4 0.3... 0.65

    8 5 0.1... 0.4

    7 9 0.7... 0.9

    2 8 0.375... 0.55

    6 9 0.9... 0.1

    ...


  • AP INVOICE approval line level

    Hi all

    My business requirement must have AP invoice approval of line level based on the applicant at each level of the line.

    I created the approver group which will be applicant ID of all the invoice lines. I joined the line level, rule.

    When launch approval, fires of workflow for the first line, and after the applicant approves the first line, the workflow triggers the process for the second line.

    (1) However, our requirement is to launch when the approval, the approval process should trigger for both lines (line 1 and line 2 in this case) at the same time.

    Please help how to achieve this goal through the installation of the SOUL.

    (2) as only one matching row details must be sent to the respective applicant when sending the notification of the approval.

    For example, the line 1 / amount USD 500 / applicant's name: ABC

    Line 2 / 200 USD amount / applicant's name: XYZ

    As of now the details of the two lines will ABC and XYZ when we need to send only line 1 with 500 USD to ABC and Line2 with 200 USD to XYZ.

    It would be really great if we get a quick response on this. Thank you very much!

    Thank you

    Partha

    I don't think that is possible with current/seeds of invoice approval workflow design.

    Approval parallel for invoices of purchases is a new feature in 12.2.4 and may be extended to the return of 12.1.x by applying the hotfix referenced in this document:

    R12: New feature approval parallel processing invoices (Doc ID 1904137.1)

    However, the new invoice approval workflow currently supports parallelism at the header level only

    Concerning

  • 2-table join

    Dear all,

    I have 2 tables say, table 1 and table 2 that looks like this.

    TABLE1:

     

    REPORT_ID

    Report_Name

    Report_Created_By

    Report_Created_On

    A

    R1

    C1

    January 1, 2013

    B

    R2

    C2

    January 2, 2014

    C

    R3

    C3

    02_Feb-2012

    D

    R4

    C4

    3 March 2016

    TABLE2

     

    Sys_ID

    REPORT_ID

    Report_Run_On

    Report_Run_By

    1

    A

    January 1, 2015

    User1

    2

    B

    January 2, 2015

    User2

    3

    A

    02_Feb-2015

    Util_3

    4

    A

    March 3, 2015

    User4

    How can I join these tables so that my resulting table looks like this,

    RESULT

     

    REPORT_ID

    Report_Name

    Report_Run_On

    (The last execution date and time)

    Report_Run_By

    (The last execution user)

    A

    R1

    March 3, 2015

    User4

    B

    R2

    January 2, 2015

    User2

    C

    R3

    D

    R4

    Thanks in advance,

    Séverine Suresh

    Hey, Sebastian,

    Séverine Suresh - 3035408 wrote:

    Dear all,

    I have 2 tables say, table 1 and table 2 that looks like this.

    TABLE1:

    REPORT_ID

    Report_Name

    Report_Created_By

    Report_Created_On

    A

    R1

    C1

    January 1, 2013

    B

    R2

    C2

    January 2, 2014

    C

    R3

    C3

    02_Feb-2012

    D

    R4

    C4

    3 March 2016

    TABLE2

    Sys_ID

    REPORT_ID

    Report_Run_On

    Report_Run_By

    1

    A

    January 1, 2015

    User1

    2

    B

    January 2, 2015

    User2

    3

    A

    02_Feb-2015

    Util_3

    4

    A

    March 3, 2015

    User4

    How can I join these tables so that my resulting table looks like this,

    RESULT

    REPORT_ID

    Report_Name

    Report_Run_On

    (The last execution date and time)

    Report_Run_By

    (The last execution user)

    A

    R1

    March 3, 2015

    User4

    B

    R2

    January 2, 2015

    User2

    C

    R3

    D

    R4

    Thanks in advance,

    Séverine Suresh

    So, you want a row of output for each row in table1, even if there is no corresponding row in table2.  This looks like a job for an outer join.

    Also, you want to only 1 row of output for each report_id, even if there are 2 or more matching rows in table2.  This sounds like a job for GROUP BY.  (I know you asked only about how to join the tables, but I think there is no harm in mentioning also GROUP BY.)

    Here's a way to do it:

    SELECT t1.report_id

    t1.report_name

    MAX (t2.report_run_on) AS lasr_run

    MIN (t2.report_run_by)

    KEEP (DENSE_RANK LAST ORDER BY report_run_on) AS last_run_by

    FROM table1 t1

    LEFT OUTER JOIN table2 t2 ON t2.report_id = t1.report_id

    GROUP BY t1.report_id

    t1.report_name

    ORDER BY t1.report_id

    ;

    If you would care to post CREATE TABLE and INSERT starements for the sample data, and then I could test this.

  • left and right outer join

    Hi gurus,

    Left outer join:

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

    Select * from A LEFT OUTER JOIN B on A.col = B.col;

    by definition, a left outer join brings the rows that match the join condition and lines not corresponding to table A.

    My question here is "corresponding to B and no matching rows in A" is that nothing, but... SELECT * FROM A;

    can someone pls clarity...

    Thank you.

    Imagine that you had:

    TableA

    COLUMN1 COLUMN2

    'A'                1

    'B'                2

    'C'                3

    TABLEB

    COLUMN1 COLUMN2

    'A'                 'X1'

    'A'                 'X2'

    'B'                 'Y'

    'D'                 'Z'

    SELECT * FROM TABLEA;

    A 1

    B 2

    C 3

    Now, if you want to join (first column is either in table A or B, (deuxieme from tableA, third table B)

    SELECT * FROM TABLEA A JOIN TABLEB B ON (A.COLUMN1 = B.COLUMN1)

    A 1 X 1

    A 1 X 2

    B 2 Y

    SELECT * FROM TABLE LEFT B EXTERNAL ON (A.COLUMN1 = B.COLUMN1) JOIN TABLE

    A 1 X 1

    A 1 X 2

    B 2 Y

    C 3 {null}

    SELECT * FROM TABLE A TABLE RIGHT OUTER JOIN B (A.COLUMN1 = B.COLUMN1)

    A 1 X 1

    A 1 X 2

    B 2 Y

    D {null} Z

    SELECT * FROM TABLE A TABLE FULL OUTER JOIN B (A.COLUMN1 = B.COLUMN1)

    A 1 X 1

    A 1 X 2

    B 2 Y

    C 3 {null}

    D {null} Z

    HTH

  • Update using sub query behavior

    I have two table with parents relationship child

    script for the same are:-

    create table pt (number);

    create table pt_ch (number b, a);

    Insert into pt values (1);

    insert into pt_ch values (2,1).

    insert into pt_ch values (3,1);

    insert into pt_ch values (4.2);

    When I execute the below the update statement, it is showing three line Update where as a condition based on I expect two rows to get the update.

    in this case for the third row that does not it updates with null, can you please tell me, why this behaves like that

    Update pt_ch set b = (select one of pt

    where pt.a = pt_ch.a);

    Select * from pt_ch;

    If there is no WHERE clause in an UPDATE statement, the update occurs on all lines. No matching rows are updated with the value NULL. This is the reason why you must always include the WHERE clause in an UPDATE STATEMENT. Try this

    Update pt_ch

    b the value = (select one of pt where pt.a = pt_ch.a)

    where exists (select null from pt where pt.a = pt_ch.a);

    or

    merge into pt_ch

    using pt

    on (pt.a = pt_ch.a)

    When matched then

    update set pt_ch.b = pt.a;

  • What means a plus sign (+) before the equal sign (=)

    Hello everyone

    This is my first post, I hope to have the opportunity with this

    I check a plsql code workmate and I try to learn what is new for me, this time I face with the notation in the second block, you can see it highlighted.

    what does the Plus Sign mean.PNG

    I have executed two of them, and I'm getting 50 records on their part.

    Is there a difference between them.

    Thanks in advance

    Hello

    In addition:

    Don't think of the (+) sign to come before the = sign; Think of it as coming after e.job_id.  In other words, the sign (+) sign applies to e.job_id, regardless of whether it is before an = sign, after one, for if there is no sign = involved.

    E EMPLOYEES

    job j

    WHERE the e.job_id (+) = j.job_id

    is equivalent to

    E EMPLOYEES

    job j

    WHERE j.job_id = e.job_id (+)

    and the two do not correspond to the

    J jobs

    LEFT OUTER JOIN employee e ON e.job_id = j.job_id

    Everything means an outer join, where the lines of the jobs table will be included whether or not they have matching rows in the employees table.

  • Cannot generate the dynamic query - ora-06502

    Hi friends,

    during execution of code below I get the error message: ora-06502 pl/sql numeric or value error on line 11

    I'm not able to open a SQL session table logging.

    DECLARE

    T_Participants TYPE TABLE IS NUMBER;

    c_Participant_Id t_Participants: = t_Participants();

    CLOB V_SQL;

    BEGIN

    Select the participantid COLLECT in BULK IN c_Participant_Id in t_roster_detail

    where rosterid = 10654

    and ba = "MD";

    I'm IN 1.c_Participant_Id.COUNT LOOP

    V_SQL: = V_SQL | "SELECT p.participantid,.

    Decode (p.Participantid, ' | c_Participant_Id (i) |', decode (p.Measureid, 10331, p.Current_Data, NULL), null) "10331_CURRENT."

    Decode (p.Participantid, ' | c_Participant_Id (i) |', decode (p.Measureid, 10331, p.Goal_Data, NULL), null) "10331_Goal."

    Decode (p.Participantid, ' | c_Participant_Id (i) |', decode (p.Measureid, 9640, p.Current_Data, NULL), null) "9640_CURRENT."

    Decode (p.Participantid, ' | c_Participant_Id (i) |', decode (p.Measureid, 9640, p.Goal_Data, NULL), null) "9640_Goal."

    Decode (p.Participantid, ' | c_Participant_Id (i) |', decode (p.Measureid, 9643, p.Current_Data, NULL), null) "9643_CURRENT."

    Decode (p.Participantid, ' | c_Participant_Id (i) |', decode (p.Measureid, 9643, p.Goal_Data, NULL), null) "9643_Goal."

    Decode (p.Participantid, ' | c_Participant_Id (i) |', decode (p.Measureid, 10332, p.Current_Data, NULL), null) "10332_CURRENT."

    Decode (p.Participantid, ' | c_Participant_Id (i) |', decode (p.Measureid, 10332, p.Goal_Data, NULL), null) "10332_Goal."

    Decode (p.Participantid, ' | c_Participant_Id (i) |', decode (p.Measureid, 10721, p.Current_Data, NULL), null) "10721_CURRENT."

    Decode (p.Participantid, ' | c_Participant_Id (i) |', decode (p.Measureid, 10721, p.Goal_Data, NULL), null) "10721_Goal."

    Decode (p.Participantid, ' | c_Participant_Id (i) |', decode (p.Measureid, 10701, p.Current_Data, NULL), null) "10701_CURRENT."

    Decode (p.Participantid, ' | c_Participant_Id (i) |', decode (p.Measureid, 10701, p.Goal_Data, NULL), null) '10701_Goal '.

    OF t_sce_msr_output_data p

    WHERE IN (SELECT T_PC_AXIS_DEFINITION CREATES CREATES

    WHERE PLANCOMPONENTID IN (SELECT PLANCOMPONENTID FROM T_PLAN_COMPONENT WHERE PLANID = 10702))

    UNION ";

    END LOOP;

    DELETE FROM T_LOGGING_SQL;

    INSERT INTO T_LOGGING_SQL VALUES (V_SQL);

    COMMIT;

    END;

    SQL > desc t_sce_msr_output_data

    Name                                      Null?    Type

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

    IDSCENARIO NOT NULL NUMBER

    CREATES NOT NULL NUMBER

    PARTICIPANTID NOT NULL NUMBER

    NUMBER OF BASELINE_DATA

    NUMBER OF CURRENT_DATA

    NUMBER OF GOAL_DATA

    You are way more complicate things here.  First of all, there is no need at all for dynamic sql because the wy you are querying is incorect.

    Even if you do not have an error, which you query will do is run the query on t_sce_msr_output_data once for each row returned by the cursor.  Each iteration of the query will return all matching rows (i.e. lines for all the participantid in the t_sce_msr_output_data table), then the external decoding will be will force all other NULL columns for all the participantid that do not correspond to the "current" participantid

    The query can be simplified to:

    Select p.participantid,

    Decode (p.Measureid, 10331, p.Current_Data, NULL) "10331_CURRENT."

    Decode (p.Measureid, 10331, p.Goal_Data, NULL) "10331_Goal."

    Decode (p.Measureid, 9640, p.Current_Data, NULL) "9640_CURRENT."

    Decode (p.Measureid, 9640, p.Goal_Data, NULL) "9640_Goal."

    Decode (p.Measureid, 9643, p.Current_Data, NULL) "9643_CURRENT."

    Decode (p.Measureid, 9643, p.Goal_Data, NULL) "9643_Goal."

    Decode (p.Measureid, 10332, p.Current_Data, NULL) "10332_CURRENT."

    Decode (p.Measureid, 10332, p.Goal_Data, NULL) "10332_Goal."

    Decode (p.Measureid, 10721, p.Current_Data, NULL) "10721_CURRENT."

    Decode (p.Measureid, 10721, p.Goal_Data, NULL) "10721_Goal."

    Decode (p.Measureid, 10701, p.Current_Data, NULL) "10701_CURRENT."

    Decode (p.Measureid, 10701, p.Goal_Data, NULL) '10701_Goal '.

    of t_sce_msr_output_data p

    where in (select creates creates

    of t_pc_axis_definition

    where plancomponentid in (select plancomponentid

    of t_plan_component

    where planid = 10702)) and

    participantid in (select participantid

    of t_roster_detail

    where rosterid = 10654 and

    BA = "MD");

    You probably want to pivot these results by participant, if so look in the note from the FAQ for the columns of the rows.

    John

  • Multi table query with key foreign null.

    Consider the following tables

    create table student (
     id number not null,
     name varchar2(80),
    primary key(id)
    );
    
    create table course(
      id number not null,
      subject varchar2(120),
      primary key(id)
    );
    
    create table class(
     id number not null,
     name varchar2(80),
     day number,
     course_id number not null,
     primary key(id),
     foreign key(course_id) references course(id)
    );
    
    create table student_course(
      id number not null,
      student_id number not null,
      course_id number not null,
      class_id number,
      primary key(id),
      foreign key(student_id) references student(id),
      foreign key(course_id) references course(id),
      foreign key(class_id) references class(id)
    );
    

    The student may enroll in a course and then a Professor assign to a class, that's why foreign class_id key isn't a constraint not null.

    What I want is to write a query so that the student can see all courses, it is registered for the class, that he has been assigned and the day of the class, but the report should include courses where the student is not assigned to a class again.

    I wrote the following query.

    select
     course.subject,
     class.name,
     class.day
    from
      course,
      class,
      student_course,
      student
    where course.id = student.course_id
    and class.id = student_course.class_id
    and student_course.foititis_id = get_foititis_id
    

    However, I only get the lines where the student_course.class_id is not null.

    I tried various combinations of coalesce, nvl, decode in both the select statement and where statement, but the results where garbage.

    No idea if such a request is possible?

    Thanks in advance for any help.

    Hello

    Thanks for posting the instructions CREATE TABLE.  Don't forget to display instructions INSERT for a litle sample data and the results desired from these sample data.

    odysam wrote:

    ... I wrote the following query.

    1. Select
    2. race. Subject,
    3. Class.Name,
    4. Class.Day
    5. Of
    6. Of course
    7. class,
    8. student_course,
    9. Student
    10. where course.id = student.course_id
    11. and class.id = student_course.class_id
    12. and student_course.foititis_id = get_foititis_id

    However, I only get the lines where the student_course.class_id is not null.

    I tried various combinations of coalesce, nvl, decode in both the select statement and where statement, but the results where garbage.

    No idea if such a request is possible? ...

    It's logical.  The condition on line 11

    Class.ID = student_course.class_id

    will not be TRUE is student.course.class_id is null.

    As Someoneelse said, looks like you need an Outer Join.

    Inner joins, as you use above, produce results only when a row in a table has one matching row in another table.

    In this case (as far as I can tell without data sample or results), you want to display the rows in a table with their matching rows When THERE is a MATCHING ROWS, but you want to show each row of the first table in any case, if corresponding lines.  This is an outer join.

Maybe you are looking for