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              

Tags: Database

Similar Questions

  • 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

  • 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 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?

  • 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

  • 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.

  • 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: -.

  • 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.

  • 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 of two tables in two different schemas

    Hi all

    I have an obligation to join two tables on two different schemas. How to join these two tables in the object view.

    Thanks in advance.

    Concerning
    Kaushik Guillaumin

    You can do just that using schema name in the +' view object.table name ' + according to the query object and also grant select the another schema to this schema user

    ex
    you need schem is test and another Act you need to a view object based on the test to join a table on shcema Act

    you write semply object sql view code:

    Act.table name

    and you can also give him select statement on Bill schem table to test

    concerning

  • How it warns Oracle to use an index for the join of two tables...

    How to prevent the Oracle to use an index for the join of two tables to get a view online that is used in an update statement?

    O.K. I think I should explain what I mean:

    When you join two tables that have many entries sometimes there're better is not to use an index on the column that is used as a criterion to join.

    I have two tables: table A and table B.

    Table A has 4,000,000 entries and table B has 700,000 entries.

    I have a join of two tables with a numeric column as join criteria.

    There is an index on this column in A table.

    So I instead of
      where (A.col = B.col)
    I want to use
      where (A.col+0 = B.col)
    in order to avoid Oracle using the index.

    When I use the join in a select query, it works.

    But when I use the join as inline in an update statement I get the error ORA-01779.

    When I remove the '+ 0' the update statement works. (The column is unique in table B).

    Any ideas why this happens?

    Thank you very much in advance for any help.

    Hartmut cordially

    You plan to use a NO_INDEX hint as shown here: http://www.psoug.org/reference/hints.html

  • display the data in two tables.

    Hi considers the following data
    WITH table1 AS
    (
      SELECT 111 userid,  To_Date('7/31/2010','mm/dd/yyyy') dt  FROM dual UNION ALL
      SELECT 111 userid,  To_Date('8/1/2010','mm/dd/yyyy') dt  FROM dual UNION all
      SELECT 111 userid,  To_Date('8/2/2010','mm/dd/yyyy') dt FROM dual UNION ALL
      SELECT 111 userid,  To_Date('8/3/2010','mm/dd/yyyy') dt  FROM dual UNION ALL
      SELECT 111 userid,  To_Date('8/4/2010','mm/dd/yyyy') dt FROM dual UNION ALL
      SELECT 111 userid,  To_Date('8/5/2010','mm/dd/yyyy') dt  FROM dual UNION ALL
    
      SELECT 222 userid,  To_Date('2/28/2010','mm/dd/yyyy') dt  FROM dual UNION all
      SELECT 222 userid,  To_Date('3/5/2010','mm/dd/yyyy') dt  FROM dual UNION all
    
    ),
     mydates AS
    (
     SELECT To_Date('7/31/2010','mm/dd/yyyy') dt1, To_Date('8/4/2010','mm/dd/yyyy') dt2 FROM dual  UNION ALL 
     SELECT To_Date('2/28/2010','mm/dd/yyyy') dt1, To_Date('3/5/2010','mm/dd/yyyy') dt2 FROM dual 
    )
    I want to join these two tables and result the following
    DT        DT2
    7/31/2010 8/04/2010
    8/01/2010  8/01/2010
    8/02/2010  8/02/2010
    8/03/2010  8/03/2010
    8/04/2010  8/04/2010
    8/05/2010  8/05/2010
    
    2/28/2010  3/5/2010
    3/5/2010   3/5/2010
    Basically, I join two tables, take dt from table1 and look into mydates. If the data match then display dt and DM2.
    If the date in table1 does not match date in t1d in mydates, then display the data but dt and DM2 there same date.

    for example,.

    7/31 in table1 is 7/31 in mydates so I show 7/31 dt and DM2 as 8/4(from mydates).
    now 8/01 does not match all lines in my dates so dt should be 8/01 and T2D should be 8/01. same logic applies to the other lines

    can someone write a query that gives the above result? Thank you

    Hello

    If you want all lines of table1 (attached to mydates when this is possible, but even when there is no match) then use an outer join:

    SELECT     t.dt
    ,     NVL (m.dt2, t.dt)     AS dt2
    FROM          table1     t
    LEFT OUTER JOIN     mydates     m     ON     t.dt     = m.dt1
    ORDER BY     t.dt
    ;
    
  • Two Tables of FACTS, some common Dimensions and common

    Hello to all, question, I'm sure you have met in the past, but always wanted to get your opinion.

    I have a few FACT tables and dimensions that are shared (common size). Rest of the dimensions are related to one or the other FACT tables.

    What is the best way to present a view where users CAN pull information from both tables?

    I managed by pulling the shared dimensions (common) on the tables of BOTH FACTS and having the same grain, but this view breaks down when I pull information from a Dimension that does not much to do with another.

    What is the best way to present it? Should it be broken down in three areas?

    Business line 1-> some Dims-> FACT Table has
    Area 2-> some Dims-> Table of FACTS B

    AND

    Business line 3-> * only commune Dims *-> Table of FACTS A & B Table of FACTS?

    Your comments are always appreciated.

    Kind regards

    Published by: user10679130 on October 12, 2009 15:27

    Start by checking the forum for similar discussions/questions.

    Join two tables of facts different dimensions in the single logical table
    http://108obiee.blogspot.com/2009/08/joining-two-fact-tables-with-different.html

    This solution maintains two tables of facts in the same area in the logical table is unique, with municipalities and non-common dimensions.

    Concerning
    Goran
    http://108obiee.blogspot.com

Maybe you are looking for