SQL: JOIN two table also corresponding column NULL how?

Hello

I'm trying to join two tables which works fine,
But if there are NULL values, then, JOIN does not.
I have two tables TEMP_DD AND TEMP_EE, in which two line
is the column: allocation A_ID,.
IE: 112 and NULL and I want both my sql output, but how?

I tried under sql as it returns only a single line of 112 and does not return a null row which is a football game.


SELECT * FROM TEMP_DD
JOIN TEMP_EE
ON (TEMP_DD.A_ID = TEMP_EE.A_ID);
How to remedy this situation?

create table TEMP_DD
(
  A_ID VARCHAR2(3),
  B_ID VARCHAR2(4),
  C_ID VARCHAR2(10)
);

create table TEMP_EE
(
  A_ID VARCHAR2(3),
  B_ID VARCHAR2(4),
  C_ID VARCHAR2(10)
);

insert into TEMP_DD (A_ID, B_ID, C_ID)
values ('112', '1123', '12345678');
insert into TEMP_DD (A_ID, B_ID, C_ID)
values (NULL, '1123', '12345678');
insert into TEMP_DD (A_ID, B_ID, C_ID)
values ('212', '1123', '12345678');


insert into TEMP_EE (A_ID, B_ID, C_ID)
values ('112', '1123', '12345678');
insert into TEMP_EE (A_ID, B_ID, C_ID)
values (NULL, '1123', '12345678');
insert into TEMP_EE (A_ID, B_ID, C_ID)
values ('312', '1123', '12345678');
OUTPUT
---------

"112', ' 1123," "12345678".
(NULL, ' 1123","12345678 ".

Hello

Wrap both sides in an NVL IE. NVL (col1, 'X'), WHERE = NVL(col2,'X').

See you soon

Ben

Tags: Database

Similar Questions

  • SQL join on the two tables where the column as another column

    Hi all


    tried to get the results of a join between two tables where only one column is like another.

    Table1 (nameA) examples: black2, green1

    Table2 (Name) example: black2.location.uk.com, green1.location.uk.com

    so, for example, I want to match all those in table1 with black2 column in table2 that begins with black2 and so of suite, if you see what im trying to get to!

    My sql up to now:
    select * from  schema.table1 a
    join schema.table2 b 
    on a.nameA like concat('%', b.nameB, '%'); 
    but it errors:

    ORA-00909: invalid number of arguments
    00909 00000 - "invalid number of arguments.

    Any help or advice would be greatly appreciated, thank you!

    Or any of them should do...

    select * from  schema.table1 a
    join schema.table2 b on a.nameA like '%'||b.nameB||'%';
    

    or

    select * from  schema.table1 a
    join schema.table2 b on instr(b.nameB,a.nameA) > 0
    
  • How to join two tables if you transpose the rows, columns and rows in one of the table

    Hi guys,.

    can someone help me please in the write request

    I have two tables

    Agents and Agent phones but in the agent phones table for the id of an agent it displays 4 rows because one of the column there types of different phones (office, mobile, home, fax)

    So instead of display 4 rows, I used max(case...) to convert rows to columns

    now how to reach it with another table

    Requirement:

    Database: 11.2.0.2.0

    create the table AGENT_PHONE

    (

    agent_id NUMBER (20) not null,

    agent_type_code VARCHAR2 (10) not null,

    agent_type_prefix VARCHAR2 (10) not null,

    Phone_Number VARCHAR2 (16) not null,

    phone_type_code VARCHAR2 (10) not null

    )

    CREATE TABLEAGENTS

    (

    agent_id NUMBER (20) not null,

    agent_type_code VARCHAR2 (10) not null,

    agent_type_prefix VARCHAR2 (10) not null,

    NAME VARCHAR2 (40) NOT NULL

    )

    INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)

    VALUES (29709, ARE ', 'OFFICE', '4805551436', 'CELL');

    INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)

    VALUES (29709, ARE ', 'OFFICE', '1111111111', 'PHONE');

    INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)

    VALUES (29709, ARE ', 'OFFICE', '2223334444',' OFF');

    INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)

    VALUES (29709, ARE ', 'OFFICE', '5556667788', 'FAX');

    INSERT INTO VALUES AGENTS

    (29709, ARE ', 'OFFICE', 'FLY');

    INSERT INTO VALUES AGENTS

    (1234, ARE ', 'OFFICE', 'MIKE');

    SELECT * FROM AGENT_PHONES

    AGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIXPHONE_NUMBERPHONE_TYPE_CODE

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

    29709REOFFICE4805551436CELL
    29709REOFFICE1111111111PHONE
    29709REOFFICE2223334444OFF
    29709REOFFICE5556667788

    FAX

    SELECT * AGENTS

    AGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIX

    NAME

    29709REOFFICEROB
    1234REOFFICE

    MIKE

    This is so the data we have in both table

    Now, I transposed rows to columns in the table of agent phones so I used the following query

    SELECT AP. AGENT_ID,. AGENT_TYPE_CODE,. AGENT_TYPE_PREFIX.

    MAX (CASE WHEN AP. PHONE_TYPE_CODE = 'CELL' THEN AP. PHONE_NUMBER END) AS CELL.

    MAX (CASE WHEN AP. PHONE_TYPE_CODE = 'OFF' THEN AP PHONE_NUMBER END) AS TURNED OFF.

    MAX (CASE WHEN AP. PHONE_TYPE_CODE = 'FAX' THEN AP. PHONE_NUMBER END) LIKE FAX,.

    MAX (CASE WHEN PHONE_TYPE_CODE = 'PHONE'. THEN AP PHONE_NUMBER END) AS PHONE

    AGENT_PHONE AP

    WHERE AP. AGENT_ID = 29709

    GROUP OF AP. AGENT_ID, AP. AGENT_TYPE_CODE, AP. AGENT_TYPE_PREFIX.

    AGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIXCELLOFFFAXPHONE
    129709REOFFICE4805551436222333444455566677881111111111

    My question is how this to join the agents table so that my output should be like this...

    I want to display all the results in the table of the Agent, even if they are not in the table of agent phones. As you can see there are other agent id 1234 is also populated

    AGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIXNAMEAGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIXCELLPHONEOFFFAX

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

    29709REOFFICEROB29709REOFFICE4805551436111111111122233344445556667788
    1234REOFFICEMIKE

    Currently, I run this query and I get the output as below

    SELECT *.

    AGENTS HAS

    LEFT OUTER JOIN AGENT_PHONE AP

    ON A.AGENT_ID = AP. AGENT_ID

    AND A.AGENT_TYPE_CODE = AGENT_TYPE_CODE.

    AND A.AGENT_TYPE_PREFIX = AGENT_TYPE_PREFIX.

    AGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIXNAMEAGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIXPHONE_NUMBERPHONE_TYPE_CODE
    129709REOFFICEROB29709REOFFICE4805551436CELL
    229709REOFFICEROB29709REOFFICE1111111111PHONE
    329709REOFFICEROB29709REOFFICE2223334444OFF
    429709REOFFICEROB29709REOFFICE5556667788FAX
    51234REOFFICEMIKE

    I want id 29709 agent in a line with 1234 agent also id to display

    You can rotate your phone number of agent in columns

    Select *.

    of AGENT_PHONE

    pivot)

    min (PHONE_NUMBER)

    for PHONE_TYPE_CODE in ('CELL' as a 'CELL', 'PHONE' like 'PHONE', 'OFF' in the 'OFF', 'FAX' as 'FAX')

    )

    AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX CELL PHONE OFF FAX
    29709 RE OFFICE 4805551436 1111111111 2223334444 5556667788

    Then you can join to view inline or CTE

    with AGENT_PHONE_PIVOT like)

    Select *.

    of AGENT_PHONE

    pivot)

    min (PHONE_NUMBER)

    for PHONE_TYPE_CODE in ('CELL' as a 'CELL', 'PHONE' like 'PHONE', 'OFF' in the 'OFF', 'FAX' as 'FAX')

    )

    )

    SELECT *.

    AGENTS HAS

    LEFT OUTER JOIN AGENT_PHONE_PIVOT AP

    ON A.AGENT_ID = AP. AGENT_ID

    AND A.AGENT_TYPE_CODE = AGENT_TYPE_CODE.

    AND A.AGENT_TYPE_PREFIX = AGENT_TYPE_PREFIX.

    AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX NAME AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX CELL PHONE OFF FAX
    29709 RE OFFICE ROB 29709 RE OFFICE 4805551436 1111111111 2223334444 5556667788
    1234 RE OFFICE MIKE - - - - - - -

    Is that what you're looking for?

  • How to join two tables to retrieve the data from the columns in table two. Tables have primary and foreign key relationships

    Hello

    I want to join the two tables to retrieve the data from the columns of the two table passing parameters to the join query. Tables have primary and foreign key relationships

    Details of the table

    Alert-1 - AlertCode (FK), AlerID (PK)

    2 AlertCode-AlertDefinition-(PK)

    Help, please


    ----------

    Hi Vincent,.

    I think that you have not worked on adf 12.1.3.  In adf 12.1.3 you don't have to explicitly create the association. When you create the EO to your table, Association xxxxFkAssoc, will be created by ADF12.1.3 for you automatically. Please try this and do not answer anything... You can also follow the links below. I solved the problem by using the following link

    Oracle ADF Guide step by step - Oracle ADF tutorial: creating a relationship of the master / detail using Oracle ADF

    ---

  • join two tables and results to display checkboxes checked... loop david powers please?

    Summary

    two tables:

    Table 1 categories

    Table 2A categories that someone has selected

    HTML form that updates the user's data:

    form should show all the options in the category dynamically in table 1

    and also to display the check box of the category as controlled dynamically if the person chose by table 2

    The nuts and bolts

    Attempt 1

    My sql:

    SELECT cat.id, cat.category, mcat.category as mcategory

    THE CAT of categories, members_categories mcat

    WHERE mcat.member_id = ' "." $_GET ['id']. »"

    ORDER BY category ASC

    (run on its own, all categories of table 1 are shown twice and the results of table 2 is a total cluster.)

    area of the form with checkboxes:

    <? PHP {? >}

    < input <? PHP if (!) ((strcmp($row_rsCategories['mcategory'],$row_rsCategories['id'])))) {echo ' checked =------'checked\' ' ;}?} > name = "category []" type = "checkbox" value = "<?" PHP echo $row_rsCategories ['id'];? ">" / > <? PHP echo $row_rsCategories ['category'];? > < br / >

    <? PHP} while ($row_rsCategories = mysql_fetch_assoc ($rsCategories));? >

    what I have here results:

    all categories displayed twice with selected categories of table 2 verified = by the results of sql when running alone

    Attempt 2

    My sql:

    SELECT cat.id, cat.category, mcat.category as mcategory

    CAT categories

    LEFT JOIN members_categories mcat WE mcat.category = cat.id

    WHERE mcat.member_id = ' "." $_GET ['id']. »"

    ORDER BY category ASC

    (run on its own, all categories of table 1 who have a match in the table 2 and none of the other in table 1 shows)

    area of the form with checkboxes:

    even the first attempt

    what I have here results:

    all categories selected in table 2 shows and checked, and no other choices of table 1 = by the results of sql when running alone

    Attempt 3

    My sql:

    SELECT cat.id, cat.category, mcat.category as mcategory

    THE CAT of categories, members_categories mcat

    WHERE mcat.member_id = ' "." $_GET ['id']. »"

    GROUP BY cat.id

    ORDER BY category ASC

    (running his own, all the choices in the category of table 1 are displayed, however, the mcategory column displays the lowest category numbered (same one) against all of these options rather then correspond to their.)

    area of the form with checkboxes:

    even the first attempt

    what I have here results:

    all choice of category in table 1 are displayed, however, only the first category in table 2 (which in this case is the lowest number) is marked as checked with the checkboxe, even if there is more then one category in table 2 = by the results of sql when running alone

    so, can anyone help?  I'm just banging my head against the wall here is something missing that should be obvious, because the sql is not giving me what I need to work with the form in a loop region.  Perhaps another approach should be taken and I have change the loop as well, but I think that this can be resolved with the sql.  Thanks in advance.

    Well, you can use two separate sql queries...

    one with the names of the categories

    and the second nested with the loop that references the id of category in table 1 to pair with table 2

  • JOIN the question... Join two tables without omitting lines

    I came across a problem that should be an easy fix (I hope), but I'm having a hard time to come up with a solution.

    Basically I have two tables, one with the actual amounts with the budget. I have to write a sql statement select that joins these tables together and includes all of their lines. I was able to join the tables by using JOIN, LEFT JOIN and RIGHT JOIN, but it always fails the lines I need.

    Below, I have examples of my tables (AMOUNT_TABLE and BUDGET_TABLE). For simplicity, I built the examples to show the same values in the first four columns, with the 5th and 6th columns (SUB_ACCOUNT, AMOUNT, BUDGET) as the only values that are different. My actual tables are not quite that simple, but I don't think it was relavent to this issue.

    AMOUNT_TABLE

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT

    2013

    111111555555000010020131111115555551000100201311111155555520001002013111111555555300010020131111115555554000100

    BUDGET_TABLE

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT BUDGET

    2013

    1111115555553000200201311111155555540002002013111111555555500020020131111115555556000200

    Here's what I hope. Note that SUB_ACCOUNTs 0000, 1000, and 2000 show without budget amounts since there is not a corresponding line in the BUDGET_TABLE. And same for SUB_ACCOUNTs 5000 and 6000, they show budgets with no amount because there is not a corresponding line in the AMOUNT_TABLE.

    (exit)

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET
    201311111155555500001000
    201311111155555510001000
    201311111155555520001000
    20131111115555553000100200
    20131111115555554000100200
    201311111155555550000200
    201311111155555560000200

    If all goes well, my question is clear. Any help on this would be greatly appreciated. Thanks in advance.

    Use the join ANSI - FULL OUTER JOIN syntax:

    with amount_table like)

    Select fiscal_year 2013, 1 period, 11111 acct_unit, 555555, 0000 sub_account, amount 100 of all the double union

    Select 2013,1,11111,555555,1000,100 from all the double union

    Select 2013,1,11111,555555,2000,100 from all the double union

    Select 2013,1,11111,555555,3000,100 from all the double union

    Select double 2013,1,11111,555555,4000,100

    ),

    budget_table like)

    Select 1 time, 11111 acct_unit, account 555555, sub_account 3000, 2013 fiscal_year, budget of 200 Union double all the

    Select 2013,1,11111,555555,4000,200 from all the double union

    Select 2013,1,11111,555555,5000,200 from all the double union

    Select double 2013,1,11111,555555,6000,200

    )

    Select nvl (a.fiscal_year, b.fiscal_year) fiscal_year,

    period of NVL (a.period, b.period),

    NVL (a.acct_unit, b.acct_unit) acct_unit.

    account of NVL (a.Account, b.Account),

    NVL (a.sub_account, b.sub_account) sub_account.

    Amount NVL(a.amount,0),

    NVL(b.budget,0) budget

    of amount_table one

    full join

    budget_table b

    on)

    a.Fiscal_Year = b.fiscal_year

    and

    a.period = b.period

    and

    a.acct_unit = b.acct_unit

    and

    a.Account = b.account

    and

    a.sub_account = b.sub_account

    )

    /

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET
    ----------- ---------- ---------- ---------- ----------- ---------- ----------
    2013 1 11111 555555 0 100 0
    2013 1 11111 555555 1000 100 0
    2013 1 11111 555555 2000 100 0
    2013 1 11111 555555 3000 100 200
    2013 1 11111 555555 4000 100 200
    2013 1 11111 555555 6000 0 200
    2013 1 11111 555555 5000 0 200

    7 selected lines.

    SQL >

    SY.

  • How to join two tables without constraints?

    I want to get back the tables to join without constraints!

    Table 1:

    get 100
    101 wet
    series 102

    and

    Table 2:

    10 xxx movies
    11 yyy
    12 zzz
    QUERY 1:

    SELECT * FROM TO LEAVE P, CUSTES C
    WHERE (P.ID, P.NAME, C.ID, C.NAME) IN (SELECT P1.ID, P1.NAME, C1.ID, C1.NAME
    OF P1, C1 CUSTES TO GO)

    I got the result like this,

    ID ID NAME
    101 wet 10 xxx
    zzz 101 wet 12
    YYY 101 wet 11
    Get 100 10 xxx
    102 the yyy 11 value
    series 102 10 xxx
    100 get 11 yyy
    100 get 12 zzz
    102 the value 12 zzz

    All ranks was sent three times! but I need to write once.

    QUERY 2:

    Select id as pid, name as the name of go
    Union
    Select id as pid, name as the name of custes;

    QUERY2 OUTPUT IS.

    NAME OF PID
    10 xxx movies
    11 yyy
    12 zzz
    get 100
    101 wet
    series 102

    In the 2nd query get the attached files of the two tables. But my need is two tables record to display like this

    ID NAME NAME_1 ID_1
    Get 10 xxx 100
    wet 11 101 yyy
    set of 12 zzz 102

    I'm looking for is, I want to join in parallel columns in my trips!

    Is there a source... ? or the same code is happy...!

    Something like that?

    WITH t1 AS (SELECT '100' id, 'get' name FROM DUAL
                UNION
                SELECT '101', 'wet' FROM DUAL
                UNION
                SELECT '102', 'set' FROM DUAL),
         t2 AS (SELECT '10' id, 'xxx' name FROM DUAL
                UNION
                SELECT '11', 'yyy' FROM DUAL
                UNION
                SELECT '12', 'zzz' FROM DUAL)
    SELECT id,
           name,
           (SELECT id
              FROM (SELECT ID, name, ROWNUM rw FROM t2) t_in
             WHERE t_in.rw = t_out.rw)
              id_1,
           (SELECT name
              FROM (SELECT ID, name, ROWNUM rw FROM t2) t_in
             WHERE t_in.rw = t_out.rw)
              name_1
      FROM (SELECT ID, name, ROWNUM rw FROM t1) t_out
    
    SQL> WITH t1 AS (SELECT '100' id, 'get' name FROM DUAL
      2              UNION
      3              SELECT '101', 'wet' FROM DUAL
      4              UNION
      5              SELECT '102', 'set' FROM DUAL),
      6       t2 AS (SELECT '10' id, 'xxx' name FROM DUAL
      7              UNION
      8              SELECT '11', 'yyy' FROM DUAL
      9              UNION
     10              SELECT '12', 'zzz' FROM DUAL)
     11  SELECT id,
     12         name,
     13         (SELECT id
     14            FROM (SELECT ID, name, ROWNUM rw FROM t2) t_in
     15           WHERE t_in.rw = t_out.rw)
     16            id_1,
     17         (SELECT name
     18            FROM (SELECT ID, name, ROWNUM rw FROM t2) t_in
     19           WHERE t_in.rw = t_out.rw)
     20            name_1
     21    FROM (SELECT ID, name, ROWNUM rw FROM t1) t_out;
    
    ID  NAME ID_1 NAME_1
    --- --- -- ---
    100 get 10 xxx
    101 wet 11 yyy
    102 set 12 zzz
    
    SQL>
    

    The number of rows in the tables are the same?

  • How to join two tables of different schemas of Oracle by using a subquery

    I'm trying to join two different schemas of Oracle tables using a subquery. I can extract data from each of the tables without problem. However, when I combine select statements it by using a subquery I get Oracle error *'ORA-00936: lack of expression ' *. Given that each SELECT statement runs on its own without error I don't understand what's missing. I'm trying to get the result set is matching the LINE_ID of PDTABLE_12_1 in the schema with the table PDTABLE_201 MAT_DESCRIPTION DD_12809 in the RA_12809 schema.

    The query is as follows:

    SQL = "SELECT [DD_12809]. [PDTABLE_12_1]. LINE_ID OF [DD_12809]. [PDTABLE_12_1] JOIN "_".
    + "(SELECT [RA_12809]. [PDTABLE_201]. MAT_DESCRIPTION "_".
    "FROM [RA_12809]. [PDTABLE_201]) AS FAB "_".
    + 'ON [DD_12809]. [PDTABLE_12_1]. PIPING_MATER_CLASS = FAB. PIPING_MATER_CLASS ".

    The format of the request is copied from a manual of programming SQL.

    I also tried running the query uses a right JOIN on the two tables, but got the same results. Any ideas would be useful. Thank you!

    Published by: user11338343 on October 19, 2009 06:55

    The format for the join of two tables in Oracle feels like any other database:

    SELECT a.col1, a.col2, ..., b.col1, b.col2, ...
    FROM   schema1.table1 a,
           JOIN schema2.table2 b ON a.col = b.col and ...
    WHERE  a.other_col = 'FRED'
    AND    ....;
    

    Do not place bracketed identifiers in Oracle. The account that connects to the database must have select privileges on the two tables.

  • unfavourable update when joining two tables

    Hello


    ORACLE VERSION
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    "CORE     11.1.0.7.0     Production"
    TNS for Linux: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production
    create the table and anonymous blocks to insert data into tables
    create table TAB_ONE(LOC_ID NUMBER,OPENDATE VARCHAR2(30),CLOSEDATE VARCHAR2(30));
    
    create table TAB_TWO(ID NUMBER,LOC_ID VARCHAR2(30),INSERTDATE VARCHAR2(30));
    
    
    
    DECLARE 
    BEGIN
    FOR I IN 1 .. 10 LOOP
    INSERT INTO TAB_ONE VALUES(i,trunc(sysdate),NULL);
    INSERT INTO TAB_ONE VALUES(i+1,NULL,NULL);
    INSERT INTO TAB_ONE VALUES(i+2,NULL,NULL);
    END LOOP;
    COMMIT;
    END;
    
    select * from TAB_ONE;
    
    DECLARE
    BEGIN
    FOR I IN 1..10 LOOP
    INSERT INTO TAB_TWO values(i,i+1,trunc(sysdate));
    END LOOP;
    COMMIT;
    END;
    
    select * from TAB_TWO;
    Here, I want to update the TAB_ONE table where opendate is null with the insertdate of TAB_TWO;

    join on LOC_ID condition.
    I tried this so far... but get SQL error: ORA-01427: einreihig subquery returns multiple rows
    01427 00000 - "einreihig subquery returns several lines.
    update TAB_ONE SET OPENDATE=(select INSERTDATE from TAB_TWO T2,TAB_ONE T1 where T2.LOC_ID=T1.LOC_ID and T1.OPENDATE is NULL)
    where  exists (select 1 from TAB_TWO T2,TAB_ONE T1 where T2.LOC_ID=T1.LOC_ID and T1.OPENDATE is NULL) and OPENDATE is NULL;
    could someone give me suggestion to acheieve this?


    Thank you
    Mike
    SQL> update TAB_ONE T1
      2  SET OPENDATE=(select INSERTDATE from TAB_TWO T2 where T2.LOC_ID=T1.LOC_ID)
      3  where T1.OPENDATE is NULL;
    
    20 rows updated.
    
    SQL> select * from TAB_ONE;
    
        LOC_ID OPENDATE                       CLOSEDATE
    ---------- ------------------------------ ------------------------------
             1 15-JUN-11
             2 15-JUN-11
             3 15-JUN-11
             2 15-JUN-11
             3 15-JUN-11
             4 15-JUN-11
             3 15-JUN-11
             4 15-JUN-11
             5 15-JUN-11
             4 15-JUN-11
             5 15-JUN-11
             6 15-JUN-11
             5 15-JUN-11
             6 15-JUN-11
             7 15-JUN-11
             6 15-JUN-11
             7 15-JUN-11
             8 15-JUN-11
             7 15-JUN-11
             8 15-JUN-11
             9 15-JUN-11
             8 15-JUN-11
             9 15-JUN-11
            10 15-JUN-11
             9 15-JUN-11
            10 15-JUN-11
            11 15-JUN-11
            10 15-JUN-11
            11 15-JUN-11
            12
    
    30 rows selected.
    

    Max

  • Join two tables for desired out put

    Hello

    I have two tables with structures below:

    TAB1:

    LEAD_NUM (PRIMARY KEY), IMPERATIVE_1, IMPERATIVE_2, IMPERATIVE_3, IMPERATIVE_4

    LEAD_NUMIMPERATIVE_1IMPERATIVE_2IMPERATIVE_3IMPERATIVE_4
    34HVJCXMNULL VALUEDGHKKK

    TAB2:

    LEAD_NUM (FOREIGN KEY), ACCOUNT_NAME, FISCAL_YEAR

    LEAD_NUMACCOUNT_NAMEFISCAL_YEAR
    34HVJATT2010
    34HVJATT2011
    34HVJATT2012

    I need the output in the format below:

    ACCOUNT_NAMELEAD_NUMFISCAL_YEARIMPERATIVES
    ATT34HVJ2010CXM, DGH, KKK
    ATT34HVJ2011CXM, DGH, KKK
    ATT34HVJ2012CXM, DGH, KKK

    Can anyone help me please with the query?

    Thanks in advance:

    Arpit

    create table TAB1

    (

    Key elementary school/LEAD_NUM varchar2 (100)

    IMPERATIVE_1 varchar2 (100),

    IMPERATIVE_2 varchar2 (100),

    IMPERATIVE_3 varchar2 (100),

    IMPERATIVE_4 varchar2 (100)

    );

    insert into tab1 values ("34HVJ", "CXM", "NULL", "DGH" 'KKK');

    create table TAB2

    (

    LEAD_NUM varchar2 (100),

    Account_name varchar2 (100)

    NUMBER OF FISCAL_YEAR

    );

    ALTER TABLE TAB2

    ADD CONSTRAINT fk_PerOrders

    FOREIGN KEY (LEAD_NUM)

    TAB1 (LEAD_NUM) REFERENCES

    INSERT INTO VALUES TAB2 ('34HVJ', 'ATT', 2010);

    INSERT INTO VALUES TAB2 ('34HVJ', 'ATT', 2011);

    SELECT t2.account_name, t2.lead_num, t2.fiscal_year,

    RTRIM (TRIM (CASE WHEN t1.imperative_1 IS NULL or t1.imperative_1 = 'NULL' THEN "ELSE t1.imperative_1 |)) ',' END |

    CASE WHEN t1.imperative_2 IS NULL or t1.imperative_2 = 'NULL' THEN ' ELSE t1.imperative_2 | ',' END |

    CASE WHEN t1.imperative_3 IS NULL or t1.imperative_3 = 'NULL' THEN ' ELSE t1.imperative_3 | ',' END |

    CASE WHEN t1.imperative_4 IS NULL or t1.imperative_4 = 'NULL' THEN ' ELSE t1.imperative_4 | (',' END), ',') requirements

    OF tab1 t1, t2 tab2

    WHERE t1.lead_num = t2.lead_num

    ORDER BY t2.fiscal_year

    Answer: -.

  • Outside to join two tables

    I had two Tables.APPROVAL_ROUTING_TAB and doc_issue_tab, where APPROVAL_ROUTING_TAB has more lines. I need to make a join of two tables such as all APPROVAL_ROUTING_TAB lines should be displayed (multiple lines) but always connect with the doc_issue_tab. I did an outer join syntax failed.
    What is the correct syntax for this.
    Key_ref takes the outline "DOC_CLASS = PR_CLASS_1 ^ DOC_NO = 1000007 ^ DOC_REV = A3 ^ DOC_SHEET = 1 ^ '.

    SELECT
    AR.line_no LINE_NO,
    AR.step_no STEP_NO,
    AR.lu_name LU_NAME,
    AR.key_ref KEY_REF,
    AR. Description DESCRIPTION,
    di. Status STATUS
    From ar APPROVAL_ROUTING_TAB, doc_issue_tab di
    WHERE
    AR.key_ref = 'DOC_CLASS =' | di. DOC_CLASS |' ^ DOC_NO =' | di.doc_no: ' ^ DOC_REV =' | di.doc_rev: ' ^ DOC_SHEET =' | di.doc_sheet: ' ^') (+)

    Thanks in advance
    Prash

    Here is an example:

    with t1 as (select 1 id, 'd1=fred^d2=john^d3=bob^' col2 from dual union all
                select 1 id, 'd1=fred^d2=john^d3=george' col2 from dual),
         t2 as (select 'fred' d1, 'john' d2, 'bob' d3 from dual union all
                select 'jim' d1, 'john' d2, 'bob' d3 from dual)
    select *
    from   t1, t2
    where  t1.col2 = 'd1='||d1(+)||'^d2='||d2(+)||'^d3='||d3(+)||'^';
    
            ID COL2                      D1   D2   D3
    ---------- ------------------------- ---- ---- ---
             1 d1=fred^d2=john^d3=bob^   fred john bob
             1 d1=fred^d2=john^d3=george              
    
  • Compare two tables that have columns of nulls and undesirable in where clause

    Table A:

    col1col2COL3COL4col5col6

    ANY

    NULL VALUE

    NULL VALUE

    YES

    YES

    YES

    NULL VALUE

    NULL VALUE

    YES

    NULL VALUE

    YES

    YES

    NULL VALUE

    ANY

    YES

    ANY

    NULL VALUE

    YES

    NULL VALUE

    NULL VALUE

    ANY

    YES

    YES

    YES

    Table B:

    col1col2COL3COL4col5col6

    ANY

    NULL VALUE

    NULL VALUE

    YES

    ANY

    YES

    ANY

    NULL VALUE

    YES

    NULL VALUE

    YES

    YES

    NULL VALUE

    ANY

    YES

    NULL VALUE

    NULL VALUE

    YES

    ANY

    NULL VALUE

    ANY

    YES

    YES

    NULL VALUE

    column values

    Yes: Current value

    No: Null

    All: Junk

    Must match all columns in TableA to TableB.

    TableA.col1 to TableB.col1

    .

    .

    .

    TableA.col6 to TableB.col6

    Any help is very appreciated

    Thank you

    Based on your last post that only good data must match exactly and your definition of junk:

    WHERE (decode (substr (A.col5, 1, 1), ' ~ ', 'junk mail', null, 'null', 12/31/9999 ', "junk," A.col5 ") = decode (substr (B.col5, 1, 1), ' ~ ', 'junk mail', null, 'null', 12/31/9999 ',"junk", B.col5"))

    AND (decode (substr (A.col6, 1, 1), ' ~ ', 'junk mail', null, 'null', 12/31/9999 ', "junk," A.col6 ") = decode (substr (B.col6, 1, 1), ' ~ ', 'junk mail', null, 'null', 12/31/9999 ',"junk", B.col6"))

    And so on for the six columns.  This assumes that this junk * still * starts with a ~.  In addition, it assumes that the unnecessary and null words are not in the form of good data.

  • Tuning for sql join key table no consumer of the heavy use of the query processor

    Obligation comes to tunne prod of the query in

    high use of the query processor

    sql_id: fp79wb32h7a6t

    Module: AHC, P_PatientDQ()

    Cost: 7

    Elapsed time: hung

    Status: Hung, 35,253,460 day at 30 minute intervals

    -Create table

    create table ahc. PATIENTVISITS

    (

    ahcid NUMBER,

    visitId NUMBER,

    visitstatus NVARCHAR2 (100),

    visitdate DATE,

    visitintime DATE,

    visitouttime DATE

    )

    -Create/recreate the index

    create indexes ahc. F1_PATIENTVISIT_AHCID on ahc. PATIENTVISITS (AHCID, VISITID);

    create indexes ahc. VISITDATE_IDX on ahc. PATIENTVISITS (TRUNC (VISITDATE));

    First total number of table

    Select count (1) of

    Pvs AHC.patientvisits

    -Save County 1387485

    create table ahc. PATIENTDEPENDENTVISITS

    (

    ahcid NUMBER (19) not null,

    IDPack NUMBER (10) not null,

    visitId NUMBER (19) not null,

    dependentvisitid NUMBER (19) not null,

    isdiabetic NUMBER (2)

    )

    -Create/recreate the index

    create indexes ahc. K1_PATIENTDEPENDENT_AHCID on ahc. PATIENTDEPENDENTVISITS (AHCID);

    Total number of second table

    Select count (1) of

    AHC.patientdependentvisits POS

    -Save County 774599

    Original request:

    SELECT count (*)

    ACH. PVS PATIENTVISITS

    WHERE PVS. VISITID IN (SELECT POS. DEPENDENTVISITID

    ACH. PATIENTDEPENDENTVISITS POS

    WHERE POS. AHCID = 37

    AND POS. VISITID = 218

    AND POS. ISDIABETIC = 0)

    AND SUPERIOR (PVS. VISITSTATUS) = 'PENDING'

    AND PVS. AHCID = 37

    Count (1)

    -----------

    1

    PL/sql Developer explain plan for the original query

    Owner of description Objects_name cost cardin bytes cpucost cost of e/s

    SELECT STATEMENT, GOAL = ALL_ROWS7141636697
    AGGREGATION OF TRI141
    SEMI OF THE NESTED LOOPS7141636697
    TABLE ACCESS BY INDEX ROWIDAHCPATIENTVISITS4125332954
    INDEX RANGE SCANAHCF1_PATIENTVISIT_AHCID39231643
    TABLE ACCESS BY INDEX ROWIDAHCPATIENTDEPENDENTVISITS3116303753
    INDEX RANGE SCANAHCK1_PATIENTDEPENDENT_AHCID214180932

    After editing the query

    SELECT / * + FIRST_ROWS * / COUNT (1)

    ACH. PVS PATIENTVISITS

    JOIN THE AHC. PATIENTDEPENDENTVISITS POS ON PVS. VISITID = POS. DEPENDENTVISITID

    WHERE PVS. AHCID = POS. AHCID

    AND POS. AHCID = 37

    AND POS. VISITID = 218

    AND POS. ISDIABETIC = 0

    AND SUPERIOR (PVS. VISITSTATUS) = 'PENDING'

    Count (1)

    -----------

    1

    PL/sql Developer explain plan for change request

    Owner of description Objects_name cost cardin bytes cpucost cost of e/s

    SELECT STATEMENT, TARGET = TIP: FIRST_ROWS7141592577
    AGGREGATION OF TRI141
    NESTED LOOPS
    NESTED LOOPS7141592577
    TABLE ACCESS BY INDEX ROWIDAHCPATIENTDEPENDENTVISITS4116366464
    INDEX RANGE SCANAHCK1_PATIENTDEPENDENT_AHCID314243643
    INDEX RANGE SCANAHCF1_PATIENTVISIT_AHCID21152932
    TABLE ACCESS BY INDEX ROWIDAHCPATIENTVISITS3125226113

    here after I changed the query no display cost = 7 io wait = improvement also 7 can someone please help these

    How to adjust or rewrite lots of join not keys to multiple records on table table

    Thank you

    VSM

    you have not answered my question. Are you really calling it 35 million times in 30 minutes?

    If so, why?

  • ALTER TABLE with the column NULL time consuming

    Hello

    I have a table with nearly 2 million documents (about 10 GB size table) when I perform the following change statement its run fast

    ALTER TABLE tbl_1 ADD (DEFAULT col_4 NUMBER 100 NOT NULL);

    but when I do not give the NOT NULL in the alter its taking a long time to complete this i.e tbl_1 of ALTER TABLE ADD (NUMBER col_4 by DEFAULT 100); once I do the column as NOT NULL.

    Can someone explain why is it happening like that regarding the execution point.

    Thanks in advance.

    I can reproduce the effect in 11.2.0.1 - but not in 12.1.0.1.

    drop table tbl_1;

    create table tbl_1

    as

    Select rownum id

    , lpad ('* ', 50,' *') padding

    of the double

    connect by level<=>

    ALTER TABLE tbl_1 ADD (NUMBER col_4 by DEFAULT 100);

    --> slow in 11.2.0.1; fast 12.1.0.1

    ALTER TABLE tbl_1 ADD (DEFAULT col_4 NUMBER 100 NOT NULL);

    --> Quick 11.2.0.1 and 12.1.0.1

    A SQL trace for two operations (11g) shows that the altar slow (without the constraint explicit non-null) made explicit (and tedious) update of any row in the table:

    Update 'TBL_1"set"COL_4"= 100

    call the query of disc elapsed to cpu count current lines

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

    Parse        1      0.00       0.02          0          1          0           0

    Run 1 11,63 33.56 8336 1016125 2053531 1000000

    Fetch        0      0.00       0.00          0          0          0           0

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

    Total 2 11,63 33,58 8336 1016126 2053531 1000000

    The other trace file does not contain the explicit Update. I guess in the optimized case that oracle stores somewhere that col_4 has the value 100 and updates only the line of the block after completing DML operations. But that's just a guess.

  • How can I join two tables that belong to two different databases?

    I can build a SQL query in SQL Server Management Studio, which performs a join of a table in a database with a table in another database.  I have a good 'read' name to username/password for the two databases.

    How to do the join in ColdFusion?  The tag < cfquery > requires a unique data source.  I could do like two queries and through comparing, or maybe even some use dbtype = query, but it would be horribly less effective than a direct join.

    I could place the SQL statement in a stored procedure, but that seems like overkill - all the necessary number of fields in the "WHERE" clause will change based on the logic of the ColdFusion program.

    Does anyone know of a way to do this with < cfquery >?

    How do you take in SQL Server Management Studio?  You must do something that I'm not aware, if what you're doing here does not work in a block.

    The way I did in the past is just to fully qualify the names of the tables.  Server.databaseOwner.database.table know if I remember correctly.

    This does not require that the database connected to the name of data source is configured to be allowed to connect to the database.

Maybe you are looking for

  • IM reimage Windows, how can I transfare/keep all my stuff in Firefox?

    Hello, once more... If shortly after restoring my system to the old point, fixing a couple of things, my system has in general been hell. Many features (explorer.exe [not IE... (EVER], Adobe Flash Player, Firefox, Skype, etc.) has been freezing, then

  • subtitles

    subtitles

  • Departure from Hi-speed on Satellite Pro C70 - B

    On my Satellite Pro C70 - B new, I put the option to hibernate the laptop when I close the screen.After a few updates, now I can't enter sleep or hibernation mode, but I have the new option start Hi-speed.But when I use this option, the system goes t

  • The application icon keeps popping up on my desktop.

    "WD Smartware" Guard icon burst on my desktop, even if my USB key is not in.  How cam I delete it from my computer completely!

  • Click and drag does not work Magic Trackpad 2

    I have a new Magic Trackpad 2, paired to a Macbook Pro (mid-2014). It works for the most part very well, but I have a big problem. Dragging never works well. For example, if I want to move a folder in the Finder to a different location, I used for a