Join several tables of two different patterns - is it possible?

If this is the case, what are the measures?

THX

This is the case.

You must prefix the tables with the schemaname tables is in, or create a synonym for the table. In addition, you must grant select rights from of a the reference schema owner schema:

SELECT A.*,B.*
  FROM SCHEMA1.TEST_TABLE A,
       SCHEMA2.TEST_TABLE B
 WHERE somecondition

Tags: Database

Similar Questions

  • 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

  • Join several Tables versioned

    Hello

    We are working on a data warehousing project and wonder how do to join several tables that each are versioned separately (type SCD 2 with a valid and valid to date).

    Because for example, we get our client from a single source of information (id customer, name, etc.) and the information on the rate of customer from another source.  The sources are different, we have the separate tables for them and each of them gets versioned independently.

    Here's my customer table (with its own valid and valuable to the columns).

    IDName of the customerValid fromValid until the
    1CitiBank1 JANUARY 14JANUARY 1, 15
    1New CitiBank2 JANUARY 15FEBRUARY 1, 15
    1Latest CitiBank2 FEBRUARY 15APRIL 1, 15

    And similarly the Client side ID and rating information.

    IDNoteValid fromValid until the
    1Platinum1 JANUARY 14FEBRUARY 1, 14
    1PremiumFEBRUARY 1, 141ST MARCH 15

    I want to merge the two tables above and present information at a glance.  I have some difficulty to determine validates the valid columns.

    IDName of the customerNoteValid from (Calculated)Valid until the (calculated)
    1CitiBankPlatinum1 JANUARY 14FEBRUARY 1, 14
    1CitiBankPremiumFEBRUARY 1, 14JANUARY 1, 15
    1New CitiBankPremium2 JANUARY 15FEBRUARY 1, 15
    1Latest CitiBankPremium2 FEBRUARY 151ST MARCH 15

    And it's the query I used to get the above result:

    SELECT client. id ,

           customer . name ,

           CRM . level ,

           Greatest (client. vld_fm , crm. vld_fm ),

           Least (client. vld_to , crm. vld_to )

    DE    client client,

           client_rating crm

      client. id = crm. id

           AND ( client. vld_fm <= crm. vld_fm

                 AND client. vld_fm <= crm. vld_to

                 AND client. vld_fm >= crm. vld_fm

                 AND client. vld_fm >= crm. vld_to )

            OR ( client. vld_fm BETWEEN crm. vld_fm AND crm. vld_to )

            OR ( client. vld_to BETWEEN crm. vld_fm AND crm. vld_to );



    The problem is we have several data sources (and each with its own versions) and joins become so very very complex.  Is there a better way to write the query?

    Or maybe a better way to design our tables?

    Thanks for your help.

    Anand

    Hello

    you only need ranges that overlap to join.

    Re: How do to sql query in a loop

    Is a simpler way to test if the x_start to x_stop range comes into conflict with the range of y_start to y_stop

    WHERE     x_start <= y_stop AND     y_start <= x_stop
    

    In other words, two overlapping if and only if everyone will start before the other ends one. If this is not obvious (and it was certainly not clear to me when I heard it), then look at it this way: two ranges are not overlapping if and only if one of them starts after the end of the other.

    Concerning

    Marcus

  • Left join between two tables using two different conditions

    I have following three tables with their data, as shown below.

    CREATE TABLE TIREMASTERPROCESS_TEMP
    (
    PRODUCTIONCODE TANK (12 BYTES),
    FIELDNAME CHAR (12 BYTES),
    DATACHR VARCHAR2 (60 BYTE),
    REVISIONNO TANK (3 BYTES),
    DATANUM NUMBER (9.4)
    )
    Whether the table c. and its sample data are like

    FIELDNAME DATACHR REVISIONNO DATANUM PRODUCTIONCODE
    AB No. Nch 1 100 0
    AB No. Nch 1 108 0
    AB No.-of-Nch 1 1 0
    Ass42 teased dishes 1 0
    Ass42 BTDrumNo1 BTD-051 1 0
    AB53 BTDrumNo1 BTD-051 104 0


    CREATE TABLE materialcode
    (
    UPPERMATERIALCODE CHAR (20),
    PROCESSNO TANK (3),
    PROCESSADOPTDATE TANK (9)

    )
    Whether the table b. and its sample data are like

    UPPERMATERIALCODE PROCESSNO PROCESSADOPTDATE
    Ass42 1 20120717
    AB53 108 20121121
    111 20111104 AS05
    104 20120928 AS30


    CREATE TABLE BUILDINGSCHEDULEMASTER
    (
    BUILDINGSIZE TANK (5 BYTES),
    GTCODE FLOAT (4 BYTES),
    TIREPERCART NUMBER (3.0).
    BUILDINGLOT NUMBER (3.0)
    )
    Whether table and its sample data are like

    BUILDINGSIZE GTCODE TIREPERCART BUILDINGLOT
    AB42A 4 12 ass42
    AB53A 4 88 AB53
    AS30A AS30 4 80
    BF03A 1 90 BF03


    Now, I need to get some data in these fields by using the suite of mappings.

    « PR_ » || Trim (a.BUILDINGSIZE) | ' / MPL2' Processid,--PRIMARY KEY
    TO_DATE (substr (NVL(b.PROCESSADOPTDATE,'19800101'), 7, 2) |) » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 5, 2) | » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 1, 4). (' 01:00:00 ',' dd-mm-yyyy hh24:mi:ss') starteff, to_date (SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 7, 2) |) » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 5, 2) | » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 1, 4). (' 01:00:00 ',' dd-mm-yyyy hh24:mi:ss') startDate.
    b.PROCESSNO revisioncodeid,
    a.BUILDINGLOT tirepercart ,
    CASE WHEN c.FIELDNAME = 'BTDrumNo1' then c.DATACHR end drumtype1.
    BOX WHEN (trim (C.DATACHR) = '1' and trim (C.FIELDNAME) = "No. Nch") and THEN click 'YES '.
    ANOTHER 'NO '.
    END may-BUG,
    case
    When c.FIELDNAME = 'Wavy'
    AND c.DATACHR = 'Use' THEN on 'YES '.
    When c.FIELDNAME = 'Wavy'
    AND c.DATACHR <>'Use' THEN 'NO '.
    fine wavy


    Now for the tables A and B I have the simple join as condition

    a.GTCODE = b.UPPERMATERIALCODE

    But I have to use two different left join conditions to join the table B and C to calculate the RESP fields according to the condition.
    Now, I have to use

    (trim (b.UPPERMATERIALCODE)). » -'|| Trim (b.PROCESSNO) = Trim (c.PRODUCTIONCODE) | » -'|| Trim (c.REVISIONNO)

    condition to get the data for the WAVY and DRUMTYPE1 fields.

    But at the same time, I have to use

    substr (Trim (b.UPPERMATERIALCODE), 1, 2). » -'|| Trim (b.PROCESSNO) = Trim (c.PRODUCTIONCODE) | » -'|| Trim (c.REVISIONNO)

    conition to derive the CHAFER field.

    And for this reason I am come so many duplicates and do not correct results for JUNEBUG, WAVY, DRUMTYPE1, and STARTDATE field.

    I need some advice as how can I do so that I get the correct results without duplicates for the PRIMARY KEY.

    Thank you

    Mahesh

    It would have been easier to answer if you gave us your example query that gives incorrect results - which both show us what you are doing and give us a starting point.
    Insert instructions for data, rather than only the data would have helped too, making it more quick to test this point.
    You do not show what you have done with your two outer join criteria, but I think you need to list TIREMASTERPROCESS_TEMP in your query twice, with alias names. Here's what I did:

    select a.BUILDINGSIZE, a.GTCODE, b.PROCESSNO ,  c1.FIELDNAME, c1.DATACHR, C2.FIELDNAME, C2.DATACHR
    , CASE WHEN c1.FIELDNAME='BTDrumNo1' then c1.DATACHR end drumtype1
    , CASE WHEN (trim(c2.DATACHR) = '1' and trim(c2.FIELDNAME) = 'No-of-Nch') THEN 'YES' ELSE 'NO' END CHAFER
    , case when c1.FIELDNAME='Wavy' AND c1.DATACHR='Use' THEN 'YES'
           when c1.FIELDNAME='Wavy' then 'NO' else null end wavy
    from BUILDINGSCHEDULEMASTER        A
    join materialcode b on a.GTCODE=b.UPPERMATERIALCODE
    left outer join TIREMASTERPROCESS_TEMP c1
       ON trim(b.UPPERMATERIALCODE)||'-'||trim(b.PROCESSNO) = trim(c1.PRODUCTIONCODE)||'-'||trim(c1.REVISIONNO)
    left outer join TIREMASTERPROCESS_TEMP c2
       ON substr(trim(b.UPPERMATERIALCODE),1,2)||'-'||trim(b.PROCESSNO) = trim(c2.PRODUCTIONCODE)||'-'||trim(c2.REVISIONNO)
    

    C1 is an alias for the TIREMASTERPROCESS_TEMP line which is necessary for drumtype1 and wavy, c2 is an alias for the TIREMASTERPROCESS_TEMP line required for JuneBug. There was some minor errors in your calculations of field I tried to correct.

    The results are:

    BUILD GTCO PRO FIELDNAME    DATACHR    FIELDNAME    DATACHR    DRUMTYPE1  CHA WAV
    ----- ---- --- ------------ ---------- ------------ ---------- ---------- --- ---
    AB53A AB53 108                         No-of-Nch    1                     YES
    AB42A AB42 1   BTDrumNo1    BTD-051    No-of-Nch    1          BTD-051    YES
    AB42A AB42 1   Wavy         NotUse     No-of-Nch    1                     YES NO
    AS30A AS30 104                                                            NO
    

    Hope this helps,
    David

  • Two constraints of primary key of a table with two different constraint name

    Hi guys

    I am creating the table below

    Table name: TITLE_COPY

    Column name Copy_id Title_id Status

    Key type

    PKPK, FK
    UniqueNN, UNN, UNN
    CheckAvailable, destroyed, leased, reserved
    Table Ref FKTitle
    FK Ref ColTitle_id
    Data typeNumberNumberVarchar2
    Length101015

    The SQL statement below can create it

    CREATE TABLE title_copy (copy_id NUMBER (10),)

    title_id CONSTRAINT NUMBER (10) title_copy_title_id_fk title (title_id) REFERENCES.

    primary key constraint title_copy_title_id_pk title_id (copy_id)

    status VARCHAR2 (15) NOT NULL CONSTRAINT status_ck CHECK (status IN ('AVAILABLE', 'DESTROYED', 'RENTAL', 'RESERVED'))

    );

    Two primary keys (title_id, copy_id) are created with the same name of constraint (title_copy_title_id_pk) (-> table-level constraint). What happens if I want to have two different names of the primary key constraint, say title_copy_title_id_pk for the title_id column and title_copy_copy_id_pk for the copy_id column?

    I can do that with a column-level constraint? Something like below (complains about the additional primary key)

    CREATE TABLE title_copy (copy_id NUMBER (10) CONSTRAINT title_copy_copy_id_pk PRIMARY KEY,)

    constraint title_copy_title_id_pk primary key (title_id).

    title_id CONSTRAINT NUMBER (10) title_copy_title_id_fk title (title_id) REFERENCES.

    status VARCHAR2 (15) NOT NULL CONSTRAINT status_ck CHECK (status IN ('AVAILABLE', 'DESTROYED', 'RENTAL', 'RESERVED'))

    );

    In summary, I can define two primary keys with the name of different constraint in a column-level constraint?

    There are no two primary keys. There is a primary key made up of two columns - also called a composite key.

    A table can have at least a primary key. You can, if you wish, create a unique constraint on a different set of columns.

  • How can I align two different text lines in the same table in two different directions (centered on one and one on the left)?

    Hello

    I want to focus the two different text lines that are in the same table, but one on the Center and the other on the left. I put a < span > tag in the hope that he was overwhelmed the family of police .bottomsel table class properties and the. Police-family Cig84 and color but the text-align only: they are both on the left.

    Here is my source and CSS codes:

    Source:

    < table width = "600" border = "0" >

    < b >

    < class td = "bottomref" > < p > < span class = "bottomsel" > | < a href = "index.html" target = "_self" > Main < /a > | " < a href = "about.html" target = "_self" > on < /a > | " < a href = "clients.html" target = "_self" > customers < /a > | " < a href = "contact.html" target = "_self" > Contact < /a > | " </span > < br / >

    < span class = 'credits' > credits: < span class = "Cig84" > Cig84 </span > < / span > < /p > < table >

    < /tr >

    < /table >

    CSS:

    {.bottomsel}

    text-align: center;

    do-family: Georgia, "Times New Roman", Times, serif;

    }

    {.credits}

    text-align: left;

    }

    . {Cig84}

    Color: #F00;

    do-family: "Comic Sans MS", cursive;

    }

    Use tags to paragraph with CSS classes.

    CSS:

    . Center {text-align: center}

    .the {text-align: left}

    HTML:

    This text is centered

    This text is left-aligned

    Nancy O.

  • Outer Join and joining several Tables

    Hello

    Oracle Database 10 g Express Edition Release 10.2.0.1.0 - product

    I have three tables AddProject, AssociateProjectLead, AddAssociate. Now I'm generating a report who will join AddProject and AssociateProjectLead for a list of all the projects, even if it doenst have a project coordinator. I used the outer join for this. However, if I want the name of the project leader, I need to search for AddAssociate table. By joining this table also, the outer join is no longer valid. Please see the result below

    CREATE TABLE  "ADDPROJECT" 
       (     "VERSIONNO" NUMBER(*,0), 
         "PROJID" VARCHAR2(20), 
         "PROJNAME" VARCHAR2(60), 
         "PROJSTARTDATE" DATE, 
         "PROJSTATUS" VARCHAR2(20), 
         "PROJENDDATE" DATE, 
         "PROJENDTYPE" VARCHAR2(20), 
         "PROJENDREASON" VARCHAR2(1000), 
         "UCPROJECTMANAGER" VARCHAR2(20), 
         "FROMDATE" DATE, 
         "TODATE" DATE, 
         "SRCHFIELD" VARCHAR2(20), 
         "OPERATOR" VARCHAR2(20), 
         "PARENTPROJID" VARCHAR2(20), 
         "PROJHIDDENDATE" VARCHAR2(20), 
          CONSTRAINT "PK_B36" PRIMARY KEY ("PROJID", "PROJHIDDENDATE") ENABLE
       )
    
    
    CREATE TABLE  "ADDASSOCIATE" 
       (     "VERSIONNO" NUMBER(*,0), 
         "ASSOCIATEID" NUMBER(9,0) NOT NULL ENABLE, 
         "ASSOCIATENAME" VARCHAR2(100) NOT NULL ENABLE, 
         "CTOJOINDATE" DATE, 
         "STATUS" VARCHAR2(20), 
         "ENDDATE" DATE, 
         "SRCHFIELD" VARCHAR2(20), 
         "OPERATOR" VARCHAR2(20), 
         "FROMDATE" DATE, 
         "TODATE" DATE, 
          CONSTRAINT "PK_B23" PRIMARY KEY ("ASSOCIATEID") ENABLE
       )
    
    CREATE TABLE  "ASSOCIATEPROJECTLEAD" 
       (     "VERSIONNO" NUMBER(*,0), 
         "PROJLEADASSOID" NUMBER(9,0), 
         "PROJID" VARCHAR2(20), 
         "ASSOCIATEID" NUMBER(9,0), 
         "PROJLEADSTARTDATE" DATE, 
         "STATUS" VARCHAR2(20), 
         "ASSOCPROJHIDDENDATE" VARCHAR2(20), 
         "PROJHIDDENDATE" VARCHAR2(20), 
         "ENDDATE" DATE, 
          CONSTRAINT "PK_B40" PRIMARY KEY ("ASSOCIATEID", "PROJID", "ASSOCPROJHIDDENDATE") ENABLE
       )
    
    
    elect ap.projid,apl.associateid
    from addproject ap, associateprojectlead apl
    where ap.projid = apl.projid(+)
    and ap.projhiddendate = apl.projhiddendate(+)
    
    
    PROJID ASSOCIATEID 
    Proj08 75825 
    Proj09 75825 
    Proj10 75825 
    Proj11 75825 
    Proj12 259811 
    Proj01 103035 
    Proj02 103035 
    Proj03 320092 
    Proj04 320092 
    Proj05 120974 
    Proj06 367393 
    Proj07 117618 
    Proj07 224882 
    Proj07 246652 
    prj001 -  
    prj001 -  
    
    16 rows returned in 0.00 seconds
    
    
    select ap.projid,apl.associateid,aa.associatename
    from addproject ap, associateprojectlead apl,addassociate aa
    where ap.projid = apl.projid(+)
    and ap.projhiddendate = apl.projhiddendate(+)
    and apl.associateid = aa.associateid
    
    
    PROJID ASSOCIATEID ASSOCIATENAME 
    Proj11 75825 Amarendra Kumar Singh 
    Proj10 75825 Amarendra Kumar Singh 
    Proj09 75825 Amarendra Kumar Singh 
    Proj08 75825 Amarendra Kumar Singh 
    Proj02 103035 Rajesh Jayaprakash 
    Proj01 103035 Rajesh Jayaprakash 
    Proj07 117618 Chetan Malhotra 
    Proj05 120974 Perumal Rajaram 
    Proj07 224882 Dilshad Ahmad 
    Proj07 246652 Shankar Kausley 
    Proj12 259811 Arunchandar Arun Vasan 
    Proj04 320092 Venkatesh Sarangan 
    Proj03 320092 Venkatesh Sarangan 
    Proj06 367393 Venkata Ramakrishna P 
    
    14 rows returned in 0.00 seconds
    How can I select all the values in table AddProject?

    Published by: Pramukh on August 23, 2012 12:18

    Hello

    I could get the result with a bit of modification

    select ap.projid,
           apl.associateid,
           aa.associatename
      from addproject ap
           left outer join
           associateprojectlead apl
        on ap.projid = apl.projid
       and ap.projhiddendate = apl.projhiddendate
           left outer join
           addassociate aa
        on apl.associateid = aa.associateid
    

    As a follow-up, I have a request more. In the report form, the user can select a particular project ID and the report should be generated as a result. For example;-he wants to see the results of the only "Proj08". I get the output as below, while the result should display only the details of 'Proj08 '.

    select ap.projid,
           apl.associateid,
           aa.associatename
      from addproject ap
           left outer join
           associateprojectlead apl
        on ap.projid = apl.projid
       and ap.projhiddendate = apl.projhiddendate
       and ap.projID = 'Proj08'
           left outer join
           addassociate aa
        on apl.associateid = aa.associateid
    ORDER BY ap.projID
    
    PROJID ASSOCIATEID ASSOCIATENAME
    Proj01 -  -
    Proj02 -  -
    Proj03 -  -
    Proj04 -  -
    Proj05 -  -
    Proj06 -  -
    Proj07 -  -
    Proj08 75825 Amarendra Kumar Singh
    Proj09 -  -
    Proj10 -  -
    Proj11 -  -
    Proj12 -  -
    prj001 -  -
    prj001 -  -  
    
  • M476dn: Printer in two different networks - is it possible?

    I got the following requirement:

    Printing from iPad should be possible on one of our network printers. As known, Apple Airprint is available only via WiFi. Question: Network printers are in another network than iPads.

    My idea:

    -Buy a Wifi capable HP printer network (for example. M476dn)

    -Configure the LAN port for normal office network (printer connected to the network via a cable)

    -Configure the printers WiFi interface for the Wifi network, which is used by iPads

    Then the PC and laptops should be able to print via normal office network (print server) and iPads via Airprint.

    Question: Is it possible to set up a printer HP in this way, so that it is located in two different networks? Especially the M476dn this would support? I would like to clarify this point of course before buying a ;-)

    In fact the user must move the network for printing.

    It is the only possible option I can think, other then get a different printer for each network.

    Kind regards

    Shlomi

  • joining several tables to generate data

    with itemlist as

    (select 1 cid, listname 'test', 'r' flg Union double all the)

    Select 2 cid, listname 'test2', ' not flg double

    ),

    category 1)

    Select 1 cid, 122 k' sub '123' catcode, of any double Union

    Select 1 cid, '234i' catcode, sub '124' all Union double

    Select 1 cid, 238 k' void '124' catcode, double

    )

    void)

    Select 1 cid, sub '123' of any union double

    Select 1 cid, sub ' 124' double

    )

    I want to write a static query that gathers all the tables and produces the following output assuming that

    CID is you pass as a parameter

    CID listname flg topic catcode

    1 123 122 k r test

    1 test of r 234i 124

    1 124 238 k r test

    Suppose the data as changes to follow and even cid 1 is to pass as a parameter:

    with itemlist as

    (select 1 cid, listname 'test', 'r' flg Union double all the)

    Select 2 cid, listname 'test2', ' not flg double

    ),

    category 1)

    Select 1 cid, 122 k' sub '123' catcode, of any double Union

    Select 1 cid, '234i' catcode, sub '124' all Union double

    Select 1 cid, 238 k' void '124' catcode, double

    )

    void)

    Select 2 cid, sub '123' of any union double

    Select 2 cid, sub '124' double

    )

    then the output should be

    CID listname flg topic catcode

    1 r test 123

    1 test of r 124

    1 test of r 124

    for a final example, suppose the data now as to user 1 as cid

    with itemlist as

    (select 1 cid, listname 'test', 'r' flg Union double all the)

    Select 2 cid, listname 'test2', ' not flg double

    ),

    category 1)

    Select 2 cid, 122 k' sub '123' catcode, of any double Union

    Select 2 cid, catcode '234i', '124' void in any union double

    Select 2 cid, 238 k' void '124' catcode, double

    )

    void)

    Select 1 cid, sub '123' of any union double

    Select 2 cid, sub '124' double

    )

    output must be

    CID listname flg topic catcode

    1       test            r                 123

    Basically, the user will pass a cid, in this case 1. I'll read the itemlist where cid = 1 and I want to join all the other tables

    to itemlist in such a way that I can generate extra lines.  If no entry is found for cid 1, for example, in category 1 or auxiliary table

    then the beloging column of this table must be null in the result

    can someone help me write a query to produce the output above

    Hello

    elmasduro wrote:

    ...

    Here is an explanation of the output.  a user will have a front screen where it can enter itemlist info.
    then in a submenu may enter a category or sub or both or none of them. the user can select multiple categories or sub
    When the user presses the button Save, an entry will be made in the itemlist table, for example the cid = 1.
    If he choose a category but without Subs, then will be entered into the table at say cid = 1


    but no entries will be made for sub because he chose not to all values.  If he chooses void instead of category values
    then sub taable will fill and category is not. If he chooses the category and under, then both will be filled.

    what I want to do is to join the itemlist with table category and sub table and get the data to the Scriptures, this intervention of the user.
    These entries not found will be the null value column in the result.
    for example, the cid = 1 itemlist, if user enter category but not void, itemlist will be the join with the table category and sub
    but since sub has no entry for the cid = 1, the column object will be empty in the output, but catcode will fill

    I'm so confused.

    It is a query (that is, just a SELECT statement, which shows the data already present in the tables), or is this a DML statement, that will add data to the tables?  If it's just a query, then do not say things like "entries will be taken" or "filled with tables.

    Assuming you want a request maybe you want something like this:

    WITH c_and_s AS

    (

    SELECT NVL (c.cid, s.cid) AS cid

    NVL (c.sub, s.sub) AS topic

    , NVL2 (s.cid, c.catcode, NULL) AS catcode

    CATEGORY 1 c

    FULL OUTER JOIN void s ON c.cid = s.cid

    AND c.sub = s.sub

    )

    SELECT i.cid, i.listname, i.flg

    cs.subject, cs.catcode

    Itemlist I have

    LEFT OUTER JOIN c_and_s ON cs.cid = i.cid cs

    WHERE the i.cid (1) - you can do the cids 2 or several at the same time, if you want to

    ORDER BY i.cid, cs.subject, cs.catcode

    ;

    This example gets the output you asked data sample you posted.

  • Joining several tables in Oracle DB

    I have the following tables.

    1 AddProject
    -PROJID
    -projName
    2 AddLab
    -Labrador
    -teacher
    3 ProjLabAssociation
    -PROJID
    -Labrador
    4 AddResearchArea
    -raID
    -raName
    5 ProjRAAssociation
    -PROJID
    -raID


    AddProject is associated with tables-AddLab and AddResearchArea
    ProjLabAssociation and ProjRAAssociation are the association of the tables that contain the primary key of the corresponding tables. The two fields in these 2 tables are primary keys.

    If AddProject has 3 entrances - (Proj1, ProjectA) (Proj2 ProjectB), (Proj3, ProjectC)
    AddLab has 2 entrances - (Lab1, Bangalore), (Lab2, Chennai)
    AddResearchArea has 2 inputs - AM1 (Green Computing) (RA2, Cloud Computing)

    ProjLabAssociation has 2 entrances - (Proj2 Lab1), (Proj3, Lab1)
    ProjRAAssociation has 3 entries - (Proj2 RA1), (Proj3, AM1), (Proj3, RA2)


    If I ask by AddLab given for (Lab1, Bangalore), I should get the following columns in the result table
    --------------------------------------------------------------------------------------------------------------------------------
    Table2ID | Table2Name | Table3ID | Table3Name | Table1ID | Table1Name
    Lab1. Bangalore | RA1 | Green Computing | Proj2 | Project b
    Lab1. Bangalore | RA1 | Green Computing | Proj3 | Project c
    Lab1. Bangalore | RA2 | Cloud Computing | Proj3 | Project c
    --------------------------------------------------------------------------------------------------------------------------------

    I tried the following commands but I m getting the expected result

    1.
    SELECT * FROM AddLab al, ProjLabAssociation pl, AddProject ap WHERE al.labID = pl.labID(+) and ap.projID = pl.projID(+);
    A SQLException exception is thrown by saying - java.sql.SQLException: ORA-01417: a table can be external joined as another table

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

    2.
    SELECT * FROM AddLab,AddProject,AddResearchArea WHERE labID in 
    (select al.labID from ProjLabAssociation pl,AddLab al  where al.labID = pl.labID)
    AND projID in
    (select ap.projID from ProjLabAssociation pl,Addproject ap where ap.projID = pl.projID)
    AND themeID in 
    (select ar.raID from ProjRAAssociation pr, AddResearchArea ar where ar.raID = pr.raID)
    AND projID in
    (select ap.projID from ProjRAAssociation pr,Addproject ap where ap.projID = pr.projID)
    ORDER BY labID;
    I do not get results expcted here

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

    Oracle version: 9i 10g / 11g

    Can anyone help me in this.

    Published by: user9205634 on December 22, 2011 03:40

    Hello

    Below the code gives the result

    with table1 as
    (
    select 'Proj1' as table1id,'ProjectA' as table1name from dual
    union all
    select 'Proj2' as table1id,'ProjectB' as table1name from dual
    union all
    select 'Proj3' as table1id,'ProjectC' as table1name from dual
    union all
    select 'Proj4' as table1id,'ProjectD' as table1name from dual
    )
    ,table2 as
    (
    select 'Lab1' as table2id,'Bangalore' as table2name from dual
    union all
    select 'Lab2' as table2id,'Chennai' as table2name from dual
    union all
    select 'Lab3' as table2id,'Delhi' as table2name from dual
    )
    , table3 as
    (
    select 'RA1' as table3id,'Green Computing' as table3name from dual
    union all
    select 'RA2' as table3id,'Cloud Computing' as table3name from dual
    )
    ,table1table2 as
    (
    select 'Proj2' as table1id,'Lab1' as table2id from dual
    union all
    select 'Proj3' as table1id,'Lab1' as table2id from dual
    union all
    select 'Proj3' as table1id,'Lab2' as table2id from dual
    union all
    select 'Proj4' as table1id,'Lab3' as table2id from dual
    )
    ,table1table3 as
    (
    select 'Proj2' as table1id,'RA1' as table3id from dual
    union all
    select 'Proj3' as table1id,'RA1' as table3id from dual
    union all
    select 'Proj3' as table1id,'RA2' as table3id from dual
    )
    select t2.table2id,t2.table2name,t3.table3id,t3.table3name,t1.table1id,t1.table1name
    from table1 t1,table2 t2,table3 t3,table1table2 jt1t2,table1table3 jt1t3
    where
    jt1t2.table2id=t2.table2id and
    t1.table1id=jt1t2.table1id and
    jt1t3.table1id(+)=jt1t2.table1id and
    t3.table3id(+)=jt1t3.table3id
    order by t2.table2name,t3.table3id;
    
    TABLE2ID TABLE2NAME TABLE3ID TABLE3NAME      TABLE1ID TABLE1NAME
    -------- ---------- -------- --------------- -------- ----------
    Lab1     Bangalore  RA1      Green Computing Proj2    ProjectB
    Lab1     Bangalore  RA1      Green Computing Proj3    ProjectC
    Lab1     Bangalore  RA2      Cloud Computing Proj3    ProjectC
    Lab2     Chennai    RA1      Green Computing Proj3    ProjectC
    Lab2     Chennai    RA2      Cloud Computing Proj3    ProjectC
    Lab3     Delhi                               Proj4    ProjectD   
    
     6 rows selected 
    

    Kind regards
    Prabhu

  • Problem with joining several tables

    Hello PL/SQL gurus and experts.

    I use Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64-bit Production version
    I followed two tables

    Student-
    drop table TT3;
    create table TT3(FeesCntlr,CommCntlr,LatePayCntlr,Name,Age) as select
    1,11,21,'Mike',25 from dual union all select
    2,12,22,'Clark',26 from dual union all select
    1,11,21,'Mike',27 from dual union all select
    4,17,27,'Ussan',28 from dual union all select
    5,13,21,'Linda',29 from dual union all select
    6,14,24,'Obrek',35 from dual union all select
    7,15,25,'Batty',45 from dual union all select
    8,16,26,'Nicky',38 from dual union all select
    1,11,21,'Mike',25 from dual union all select
    2,12,22,'Clark',26 from dual union all select
    1,11,21,'Mike',27 from dual union all select
    4,17,27,'Ussan',28 from dual union all select
    5,13,21,'Linda',29 from dual union all select
    6,14,24,'Obrek',35 from dual union all select
    7,15,25,'Batty',45 from dual union all select
    8,16,26,'Nicky',38 from dual ;
    Fees-
    drop table TT4;
    create table TT4(FeesCntlr,CommCntlr,LatePayCntlr,Fees,Commission,Latepayment) as select
    1,11,21,25000,4456,223 from dual union all select
    2,12,22,356000,3321,0 from dual union all select
    1,11,21,456000,223,33 from dual union all select
    4,17,27,32890,0,0 from dual union all select
    5,13,21,0,778,223 from dual union all select
    6,14,24,332567,222,0 from dual union all select
    7,15,25,228990,22,0 from dual union all select
    8,16,26,0,0,2234 from dual union all select
    1,11,21,22345,0,0 from dual union all select
    2,12,22,2222789,2,33 from dual union all select
    1,11,21,334567,0,0 from dual union all select
    4,17,27,9987250,2,33 from dual union all select
    5,13,21,2227890,0,0 from dual union all select
    6,14,24,2278231,0,3345 from dual union all select
    7,15,25,223456,2,0 from dual union all select
    8,16,26,223890,0,0 from dual ;
    I am looking forward to the fees, commissions and surcharges output for each student and by using the following SQL code.
    select t3.Name,t3.age,t4.Fees
    from tt3 t3, tt4 t4
    where t3.FeesCntlr=t4.FeesCntlr
    union
    select t3.Name,t3.age,t4.Commission
    from tt3 t3, tt4 t4
    where t3.CommCntlr=t4.CommCntlr
    union
    select t3.Name,t3.age,t4.Latepayment
    from tt3 t3, tt4 t4
    where t3.LatePayCntlr=t4.LatePayCntlr
    but it gives me not the correct result and showing a lot of entries and display only the "Expenses" column then only I'm looking for the output to be -
    Name     Age     Fees          Commission     Laypayment
    Mike     25     837912          4679          256
    Clark     26     2578789          3323          33
    Ussan     36     10020140     2          33
    Linda     38     2227890          778          223
    Obrek     38     2610798          222          3345
    Batty     32     452446          24          0
    Nicky     23     223890          0          2234
    Kindly help me with this. Thank you in advance for your time and effort.

    Hello

    I see your table TT3 has duplicated lines. A reason for this?

    Rather than run a separate, I created it without duplicated lines:

    create table TT3(FeesCntlr,CommCntlr,LatePayCntlr,Name,Age) as select
    1,11,21,'Mike',25 from dual union all select
    2,12,22,'Clark',26 from dual union all select
    4,17,27,'Ussan',28 from dual union all select
    5,13,21,'Linda',29 from dual union all select
    6,14,24,'Obrek',35 from dual union all select
    7,15,25,'Batty',45 from dual union all select
    8,16,26,'Nicky',38 from dual;
    
    create table TT4(FeesCntlr,CommCntlr,LatePayCntlr,Fees,Commission,Latepayment) as select
    1,11,21,25000,4456,223 from dual union all select
    2,12,22,356000,3321,0 from dual union all select
    1,11,21,456000,223,33 from dual union all select
    4,17,27,32890,0,0 from dual union all select
    5,13,21,0,778,223 from dual union all select
    6,14,24,332567,222,0 from dual union all select
    7,15,25,228990,22,0 from dual union all select
    8,16,26,0,0,2234 from dual union all select
    1,11,21,22345,0,0 from dual union all select
    2,12,22,2222789,2,33 from dual union all select
    1,11,21,334567,0,0 from dual union all select
    4,17,27,9987250,2,33 from dual union all select
    5,13,21,2227890,0,0 from dual union all select
    6,14,24,2278231,0,3345 from dual union all select
    7,15,25,223456,2,0 from dual union all select
    8,16,26,223890,0,0 from dual ;
    
      SELECT t3.name, t3.age, SUM (t4.fees) fees, SUM (t4.commission) commission
           , SUM (t4.latepayment) latepayment
        FROM tt3 t3, tt4 t4
       WHERE     t3.feescntlr = t4.feescntlr
             AND t3.commcntlr = t4.commcntlr
             AND t3.latepaycntlr = t4.latepaycntlr
    GROUP BY t3.name, t3.age;
    
    Output:
    NAME         AGE       FEES COMMISSION LATEPAYMENT
    ----- ---------- ---------- ---------- -----------
    Mike          25     837912       4679         256
    Ussan         28   10020140          2          33
    Linda         29    2227890        778         223
    Clark         26    2578789       3323          33
    Obrek         35    2610798        222        3345
    Nicky         38     223890          0        2234
    Batty         45     452446         24           0
    

    Kind regards.
    Al

    Published by: Alberto Faenza on November 6, 2012 12:40

  • How to join several tables source and do the research?

    I have a requirement to load a target table by joining 4 source tables. Also, I do a search on a field of table to transform codes and check for NULL values. What will be the best approach for load table target?
    Is it possible to do it in a single interface, or do I need to create multiple interfaces to achieve this?

    My basic source and target are oracle, and I am planing to use incremental update Oracle merge.

    Thank you

    You are in the right direction by creating an interface for this transformation.
    You will need to drag the source drop 4 tables + the lookup table in the Sources of Interface window and then make the appropriate joins.
    Also, look for NULL values in the transformation. Depends on what you want to do with NULL values. If you want to ignore, use a filter.
    If you want to make mistakes, use a constraint.
    If you want to convert them, use NVL

    Start with Oracle Update incremental and once successful, use incremental update Oracle MERGE.

  • Retriving data by joining several tables and total general

    Hello PL/SQL gurus and experts.

    I use Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64-bit Production version
    I have table-

    I have the following three tables
    DROP TABLE Person_Tb;
    create table Person_Tb(Person_ID,Person_FName,Person_LName) as select
    1001, 'Nikki','Carlos' from dual union all select
    1002, 'Nina', 'Harrison' from DUAL union all select
    1003, 'Mike', 'Carwely' from dual union all select
    1004, 'Michael', 'Robinson' from DUAL union all select
    1005, 'Hendi', 'Klum' from dual union all select
    1006, 'Robert', 'Regan' from dual union all select
    1007, 'Maria', 'Washington' from dual union all select
    1008, 'Kistrien', 'Obama' from dual union all select
    1009, 'Andrew', 'Regan' from dual union all select
    1010, 'Emma', 'Thomsan' from dual union all select
    1011, 'Andy', 'Grant' from dual union all select
    1012, 'Brandy', 'Decosta' from dual;
    DROP TABLE Teacher;
    create table Teacher(Teacher_ID,Fee_Date,Account_ID) as select
    1001, '04/04/2013',3004 from dual union all select
    1002, '04/06/2013',3006 from DUAL union all select
    1003, '04/08/2013',3014 from dual union all select
    1004, '04/08/2013',3017 from DUAL union all select
    1005, '04/09/2013',3019 from dual union all select
    1011, '04/12/2013',3025 from dual union all select
    1012, '04/12/2013',3046 from DUAL;
    DROP TABLE Student;
    create table Student(Student_ID,Subaccount_ID) as select
    1006,3004 from dual union all select
    1007,3006 from DUAL union all select
    1008,3004 from dual union all select
    1009,3017 from DUAL union all select
    1010,3017 from dual;
    I am able to recover the data individually Tracher and student as -.
    Select distinct pt.Person_LName || ',' ||
                                           pt.Person_FName Trdr_NM
                                      from Student st, person_Tb pt
                                     where st.Student_id = pt.PERSON_ID
    Select distinct pt.Person_LName || ',' ||
                                           pt.Person_FName SubAct_Invst
                                      from Teacher  tc, person_Tb pt
                                     where tc.teacher_id = pt.PERSON_ID
    I need to get the records for all teachers who are associated with students-
    SubAct_Invst     Trdr_NM
    ----------------------------------------------------
    Carlos,Nikki 
              Regan,Robert
              Obama,Kistrien
    Harrison,Nina
              Washington,Maria
    Carwely,Mike
    Robinson,Michael
              Regan,Andrew
              Thomsan,Emma
    Klum,Hendi
    Grant,Andy
    Decosta,Brandy
    ------------------------------------------------------
    Grand Total
    7                                5
    But how to retrieve the data above format, many want to help. Thanks in advance and I really appericate your time and efforts.

    Ideally, your condition must be handled by a front-end tool...

    If you need specifically using SQL, you can check my previous post...

  • Comparing the same tables of two schemas

    I had already posted a similair on this thread. So, I thought I would start a new thread on this to avoid confusion

    I want to generate a report that shows the difference in the data type of the columns in the same table in two different patterns.

    The query using LESS shows the difference below.

    create table SCOTT.mytab1 (empid number);
    create table HR.mytab1 (empid varchar2(34));
    
    
    SELECT   table_name, column_name, OWNER schema, data_type
    FROM     dba_tab_cols where owner = 'SCOTT'
    AND TABLE_NAME = 'MYTAB1'
    MINUS
    SELECT   table_name, column_name, OWNER schema, data_type
    FROM     dba_tab_cols where owner = 'HR'
    AND TABLE_NAME = 'MYTAB1'
    
    Result:
    TABLE_NAME      COLUMN_NAME     SCHEMA     DATA_TYPE
    --------------- --------------- ---------- ------------
    MYTAB1          EMPID           SCOTT      NUMBER
    But, since it is a report, I want to see the form of results the two schemas that has column of different data types with the same names of table

    Expected results:
    TABLE_NAME      COLUMN_NAME     SCHEMA     DATA_TYPE
    --------------- --------------- ---------- ------------
    MYTAB1          EMPID           SCOTT      NUMBER
    MYTAB1          EMPID           HR         VARCHAR2
    Anyway I could do this?

    Why not get a single line with two types of data:

    select a.table_name, a.column_name, a.data_type schema1_type, b.data_type schema2_type
    from all_tab_columns a, all_tab_columns b
    where a.owner = 'SCOTT'
    and b.owner = 'HR'
    and a.table_name=b.table_name
    and a.column_name=b.column_name
    and a.data_type!=b.data_type;
    

    This extracted single query columns present on the two schemas but with different data types. These columns only on one of the two schemas are not extracted.

    Max

  • Outer join, 3 tables

    Please see the attached link for table structures and data of the sample.

    There will be several lines in the table of SALES with different SALETYPEs. There may be several lines in the table RETURNS, corresponding to some of the points of SALE. RETURNS the table has a foreign key to the SALE. The report that I am trying to generate with a select sql statement must include a line for each type of sale (from table SALETYPE) and the sum of sale amounts corresponding to this type of sale of the SALES table. The table may not return the entries for all types of sales and the amount of Scripture must be reported as zero. The SQL I use is below, but does not work. I hope that I have explained this correctly. Please see the doc attached for typical data that I work with. Can someone please?

    https://spreadsheets.Google.com/pub?key=0AnDmnUJXOChwdGF2ZjdjdHFtMGF1MkJ3MWtjQ2JfUmc & hl = in & Single = true & gid = 0 & output = html

    Select SUM (s.amount) as sum_amount, t.sale_type from SALES s, SALETYPE t, r RETURNS
    where s.id = r.id
    and s.sale_type_id = t.id
    T.sale_type group;

    Published by: 801941 on October 12, 2010 15:02

    Hello - the second displays almost had. what you want to do is joining several tables at once - impossible with the syntax of the oracle, but possible if you use ANSI SQL.

    Wrote file afiedt.buf
    
      1  WITH s AS
      2   (SELECT 1 id, 1 sale_type_id, 10 amount   FROM dual
      3    UNION ALL
      4    SELECT 2, 1, 10  FROM dual
      5    UNION ALL
      6    SELECT 3, 2, 10   FROM dual
      7    UNION ALL
      8    SELECT 4, 2, 10   FROM dual
      9    UNION ALL
     10    SELECT 5, 3, 10    FROM dual
     11    UNION ALL
     12    SELECT 6, 4, 10 FROM dual),
     13  r AS
     14   (SELECT 2 sale_id   FROM dual
     15    UNION ALL
     16    SELECT 3 FROM dual
     17    UNION ALL
     18    SELECT 4 FROM dual),
     19  t AS
     20   (SELECT 1 sale_type_id, 100 sale_type    FROM dual
     21    UNION ALL
     22    SELECT 2, 200    FROM dual
     23    UNION ALL
     24    SELECT 3, 300    FROM dual
     25    UNION ALL
     26    SELECT 4, 400 FROM dual)
     27  SELECT nvl(SUM(s.amount),0) total_amount, t.sale_type
     28    FROM t
     29     join r on (1=1)
     30     left outer join s on (s.id = r.sale_id and s.sale_type_id = t.sale_type_id)
     31   --WHERE s.id(+) = r.sale_id
     32  --   AND s.sale_type_id(+) = t.sale_type_id
     33   GROUP BY t.sale_type
     34*  order by t.sale_type
    SQL> /
    
    TOTAL_AMOUNT  SALE_TYPE
    ------------ ----------
              10        100
              20        200
               0        300
               0        400
    
    4 rows selected.
    

    The two commented lines are what you are trying to achieve using the syntax of the oracle, but which will give you an error.

Maybe you are looking for