Join  a Parent Table with 2 Child table based on a value

Dear Guru's
We have a Parent Table and 2 Child table . The Parent Table has a column like seqtype with only 2 possible values C and S . If the Value is C , then the details are available in Child 1 table and if the Value is S then the Details are in Child 2 table
How can we query the Data from this type of arrangement ? I am little bit confused and hit a road block
Will the following query will work ?
Select
from Parent P , Child C1, Child C2
where P.seqtype = C1.Seqtype
and P.seqtype = C2.Seqtype
With Warm Regards
ssr

You didn't mention the column names in two child tables. Whether the columns are same in 2 tables of these are different.
If the columns are same better to go and change your design to have only one child table. However if stiil business stops you having one table you can use UNION ALL (Assuming you want to fetch same column information from two child tables) like below:
SELECT p.col1
      ,c1.col2
      ,c1.col3
      ,c1.col4
  FROM parent     p
      ,child      c1
WHERE p.seqtype = c1.seqtype
UNION ALL
SELECT p.col1
      ,c2.col2
      ,c2.col3
      ,c2.col4
  FROM parent     p
      ,child      c2
WHERE p.seqtype = c2.seqtype Regards
Arun

Similar Messages

  • Recreating a table with child table dependencies

    Hi.
    I have two tables P (Parent) and C (child), with foreign key dependencies. How can I recreate the P table without losing the child dependencies?
    Thanks in Advance.

    934086 wrote:
    Well I got this as an interview question. So what I guess what it means is to recreate the table for administrative purposes (maintenance/defragmentation etc) and later recreate the dependencies in to the C table.If this is a good interviewer, they will be expecting you to ask some questions to find out the restrictions on what you're allowed to do.
    Obviously you could extract any dependency information from the data dictionary, so it won't be "lost". Then you could switch the database into restricted mode and/or shut down the listener. Drop any RI constraints, recreate table, recreate constraints, restart listener, take database out of restricted mode. However, this might be a catastrophic strategy from the perspective of the business - so if you try to answer the question without first asking questions (or at least starting with "there are various methods, depending on the restrictions you need to impose from a business perspective, for example ...)
    Regards
    Jonathan Lewis

  • Hello Gurus..... ISSUE with child Table update

    I have an issue with child table update
    I have created a GTC with one parent table and two child tables. I'm able to update the parent table and the values are found in db, but the ISSUE is the child Table values are not updating the db.
    please give me a solution
    regards
    Srikanth

    If you are keeping referential integrity in the database, not in the application, it is easy to find the child and parent tables. Here is a quick and dirty query. You can join this to dba_cons_columns to find out on which columns the referential constraints are defined. This lists all child-parent table including SYS and SYSTEM users. You can run this for specific users of course.
    select cons1.owner child_owner,cons1.table_name child_table,
    cons2.owner parent_owner,cons2.table_name parent_table
    from dba_constraints cons1,dba_constraints cons2
    where cons1.constraint_type='R'
    and cons1.r_constraint_name=cons2.constraint_name;

  • Join Istore table with AR tables

    Hi Gurus,
    How to join ibe_msites_b table with AR table. I am trying to get list of all customers from different mini sites. These are the AR tables i am using
    HZ_Cust_Accounts
    HZ_Parties
    Regards,

    The following query should give you resullts for B2C. Change the query based on your requirement incase if you want it for B2B. Please note that I haven't added alll the conditions. This should be your starting point.
    Hope this helps,
    RK
    SELECT imt.msite_name,
    hp.party_name
    FROM jtf_um_subscription_reg jusr,
    jtf_um_subscription_resp jure,
    fnd_responsibility fr,
    ibe_msite_resps_b imrb,
    ibe_msites_tl imt,
    fnd_user fu,
    hz_parties hp
    WHERE jusr.subscription_id = jure.subscription_id
    AND jure.responsibility_key = fr.responsibility_key
    AND fr.responsibility_id = imrb.responsibility_id
    AND imrb.msite_id = imt.msite_id
    AND imt.language = USERENV('LANG')
    AND fu.user_id =jusr.user_id
    AND fu.person_party_id = hp.party_id

  • Help in joining nested table with regular table

    Im creating a nested table codelist as object prtcnpt_info. In a anonymous block im declaring t_code as nested table type codelist.
    Now when i try to join the nested table with the regular oracle DB table and i get error: PL/SQL: ORA-00904: "COLUMN_VALUE": invalid identifier.
    Please help me on this and provide tutorial link pertaining to this concepts..Below is the code i wrote
    --Code Start;
    create or replace type prtcnpt_info as object ( id number
    ,name varchar2(200)
    ,code varchar2(30));
    create type codelist is table of prtcnpt_info;
    declare
    t_code codelist;
    begin
    select prtcnpt_info(b.pid ,b.name ,pt.code) bulk collect into t_code
    from part pt
    ,mc_code b
    where pt.cd in ('AAA','BBB')
    and pt.ptype_id=b.pt_type_id;
    INSERT INTO table ( ID
    ,RUN_ID
    ,DATA
    ,P_ID
    SELECT id
         ,run_id
         ,data
         ,prtct.id ----> 1
    FROM table_2 t2
    ,(select column_value from table(t_code)) prtct
    WHERE prtct.id=t2.P_ID; ------> 2
    end;
    --Code End;
    also from the anonymous block
    1 => is this correct way to get value of id (b.pid) from the nested tablet_code aliased as prtct ?
    2 => is this correct way to join the nested table with regular table? i want to join the column id's in both the tables.
    Edited by: 914912 on Apr 30, 2012 2:11 AM

    When you create a table type without an object, i.e. a single column type like this you will get the column name as COLUMN_VALUE.
    SQL*Plus: Release 10.2.0.5.0 - Production on Mon Apr 30 07:38:32 2012
    Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> create or replace type mytbl as table of varchar2(10)
      2  /
    Type created.
    SQL> var rc refcursor
    "afiedt.buf" 11 lines, 162 characters
      1  declare
      2     ltbl mytbl;
      3  begin
      4     select to_char(level) bulk collect into ltbl
      5       from dual
      6    connect by level <= 10;
      7     open :rc for
      8     select * from table(ltbl);
      9* end;
    10  /
    PL/SQL procedure successfully completed.
    SQL> print rc
    COLUMN_VAL
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    10 rows selected.And when you create a table type with object you will get the object column name.
    SQL> drop type mytbl
      2  /
    Type dropped.
    SQL> create type myobj as object (id varchar2(10))
      2  /
    Type created.
    SQL> create type mytbl as table of myobj
      2  /
    Type created.
    SQL> declare
      2     ltbl mytbl;
      3  begin
      4     select myobj(to_char(level)) bulk collect into ltbl
      5       from dual
      6    connect by level <= 10;
      7     open :rc for
      8     select * from table(ltbl);
      9  end;
    10  /
    PL/SQL procedure successfully completed.
    SQL> print rc
    ID
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    10 rows selected.
    SQL>

  • How to join PLSQL nested table with normal tables ?

    my requirement is to delete the rows in a normal oracle table in one statement, based on the values collected in a PL/SQL nested table which is filled by another program.
    In the following example, i need to delete the rows in
    the table c_journals where the columns branch_code and
    id are having values which exist in the PL/SQL
    nested table's columns a and b respectively
    declare
    type test_type IS RECORD (a VARCHAR2(20), b number(20));
    type test_table is table of test_type index by binary_integer;
    test_object test_table;
    cnt number;
    begin
    test_object(1).a := '1000';
    test_object(1).b := 1;
    test_object(2).a := '1006';
    test_object(2).b := 4;
    /* to be completed */
    delete c_journals where ....
    end;
    Is this possible in Oracle ? Iam using the version 9iR2
    Thanks in advance

    Both of the following delete statements should work. For the second the two types need to be created as database objects.
    declare
      type test_type IS RECORD (a VARCHAR2(20), b number(20));
      type test_table is table of test_type index by binary_integer;
      test_object test_table;  -- := test_table(test_type('1000',1), test_type('1006',4));
      cnt number;
    begin
      test_object(1).a := '1000';
      test_object(1).b := 1;
      test_object(2).a := '1006';
      test_object(2).b := 4;
      for i in test_object.first .. test_object.last loop
        delete from c_journals cj
        where test_object(i).a = cj.branch_code
         and test_object(i).b = cj.id;
      end loop;
    end;
    create or replace type test_type IS object (a VARCHAR2(20), b number(20));
    create or replace type test_table is table of test_type;
    declare
      test_object test_table := test_table(test_type('1000',1), test_type('1006',4));
      cnt number;
    begin
      delete from c_journals cj
      where exists (select 'x' from table(cast(test_object as test_table)) t
         where cj.branch_code = t.a and cj.id = t.b);
    end;
    /

  • Partition exchange error on table with nested table

    On Oracle 11.2.0.1, I have a partitioned table with some partitions that need to be 'archived' (in terms of moving partitions to an 'archive' table).
    I have a source table like:
    CREATE TABLE IS_PODACI245
      ID_OBJEKTA_IDENTIFIKACIJA  NUMBER(10),
      ID_OBJEKTA                 NUMBER(20),
      DATUM                      TIMESTAMP(6)       NOT NULL,
      TZ                         NUMBER(3),
      DATA1                      NUMBER(10),
      DATA2                      NUMBER(6),
      DATA3                      NUMBER(10),
      DATA4                      NUMBER,
      DATA5                      T_NTCIP_CLIMATE_TABLE
    NESTED TABLE DATA5 STORE AS IS_PODACI245_STORE_TABLE
    TABLESPACE DATA
    PARTITION BY RANGE (DATUM)
      PARTITION P_201107 VALUES LESS THAN (TIMESTAMP' 2011-08-01 00:00:00')
        LOGGING
        NOCOMPRESS
        TABLESPACE DATA, 
      PARTITION P_MAXVALUE VALUES LESS THAN (MAXVALUE)
        LOGGING
        NOCOMPRESS
        TABLESPACE DATA
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    MONITORING;
    CREATE INDEX IDX_IS_PODACI245_KOMPLEKS ON IS_PODACI245
    (ID_OBJEKTA_IDENTIFIKACIJA, ID_OBJEKTA, DATUM)
      TABLESPACE DATA
    LOCAL ( 
      PARTITION P_201107
        LOGGING
        NOCOMPRESS
        TABLESPACE DATA, 
      PARTITION P_MAXVALUE
        LOGGING
        NOCOMPRESS
        TABLESPACE DATA
    NOPARALLEL;
    CREATE OR REPLACE TYPE t_ntcip_climate_table as table of t_ntcip_climate_fmt;
    CREATE OR REPLACE TYPE t_ntcip_climate_FMT as object
    (  dev_index number(6)
    ,   dev_description varchar2(512)
    ,   dev_type number(10)
    ,   dev_status number(10)
    ,   dev_mfr_status varchar2(512)
    ,   dev_active number(3)
    ,   dev_test_activation number(10)
    /I would like to make exchange partition using stage table, and everything is going fine on all tables, but only on a few of them (listed source is one of them, and they're only tables with nested tables wihin), where I get an error.. but sometimes ;)
    on a statement like:
    ALTER TABLE IS_PODACI245_ARH EXCHANGE PARTITION P_201106  WITH TABLE IS_PODACI245_STAGE EXCLUDING INDEXES  WITHOUT VALIDATION;I got an error:
    ORA-00001: unique constraint (TXV.SYS_C0032911) violated
    it's an unique index between parent and nested table.
    what could cause that problem?

    Dear,
    I suppose that the unique constraint
    ORA-00001: unique constraint (TXV.SYS_C0032911) violatedis the one you 've created on the nested table IS_PODACI245_STORE_TABLE
    If so, why not disable that constraint and try again.
    I have never exchanged such a kind of partitioned table having a nested table in it. But, I could imagine that the cloned non partitioned table IS_PODACI245_STAGE should at least be the exact image of the partitioned table IS_PODACI245_ARH (of course without the partition part) but with the nested table part and including all indexes
    In addition, if you have a parent/child relationship between your partitioned tables, then there is a chronological order of exchange starting by the child and then finishing by the parent
    see the following link for more information about this order of exchange (and comment 2 for an example also)
    http://jonathanlewis.wordpress.com/2006/12/10/drop-parent-partition/#more-65
    Hope this helps
    Mohamed Houri

  • Mix object tables with relational tables?

    Hallo,
    is it possible to mix object tables with relational tables in one database?
    I didn't succeed in assigning a foreign key from a relational table to an object table.
    Is this only working with column objects in relational tables?

    Hi
    is it possible to mix object tables with relational tables in one database?
    Every database contains both types of tables. So, it is basically not a problem.
    I didn't succeed in assigning a foreign key from a relational table to an object table.
    Is this only working with column objects in relational tables?It would be interesting to know how you tried... e.g. what error you get... Here an example (executed on 11.1).
    SQL> create or replace type tt as object ( n number );
      2  /
    SQL> create table ot of tt (constraint ot_pk primary key (n));
    SQL> create table rt (n number, constraint rt_ot_fk foreign key (n) references ot (n));
    SQL> insert into ot values (tt(1));
    SQL> insert into rt values (1);
    SQL> insert into rt values (2);
    insert into rt values (2)
    ERROR at line 1:
    ORA-02291: integrity constraint (OPS$CHA.RT_OT_FK) violated - parent key not foundHTH
    Chris

  • How to link TCJ_Documents table with BKPF table

    Dear all,
    i am new ABAPer, i need to join TCJ_Documents table with BKPF table.
    but, i can not find the relationship between this two tables.
    so, please help !
    thanks !

    Hi....
    There is a company code (BUKRS) in both tables.
    Also Fiscal year(GJAHR)...
    What is the problem with that?
    Sample code...
    data: begin of itab occurs 0,
          bukrs type bukrs,
          cjnr type cjnr,
          belnr type belnr_d,
          end of itab.
    start-of-selection.
    select p~bukrs p~belnr q~comp_code from bkpf as p
           inner join tcj_documents as q
           on p~bukrs = q~comp_code
           into table itab.
    loop at itab.
      write:/ itab-bukrs.
    endloop.
    Thanks,
    Naveen.i

  • Import tables with nested table : ORA-00600

    In Oracle 9.2
    Create object, type as table, and table with nested table (store as syms_ntab) are successfully.
    Also its export.
    In process of import on another server (also 9.2, 'fromuser=one touser=two') shows errors:
    . . importing table "SYMS_NTAB"
    IMP-00058: ORACLE error 600 encountered
    ORA-00600: internal error code, arguments: [kokeeafi1], [2], [2], [], [], [], [], []
    IMP-00075: Warning: The nested table may contain partial rows or duplicate rows
    But for all that table is created and error occur on phase inserting strings.
    What is this?
    In Oracle 8.0.5 i perform similar operation without error.

    From Oracle error messages and codes manual:
    ORA-00600 internal error code, arguments: [string], [string], [string], [string], [string], [string], [string], [string]
    Cause: This is the generic internal error number for Oracle program exceptions. It indicates that a process has encountered a low-level, unexpected condition. Causes of this message include:
    * timeouts
    * file corruption
    * failed data checks in memory
    * hardware, memory, or I/O errors
    * incorrectly restored files
    The first argument is the internal message number. Other arguments are various numbers, names, and character strings. The numbers may change meanings between different versions of Oracle.
    Action: Report this error to Oracle Support Services after gathering the following information:
    * events that led up to the error
    * the operations that were attempted that led to the error
    * the conditions of the operating system and databases at the time of the error
    * any unusual circumstances that occurred before receiving the ORA-00600 message
    * contents of any trace files generated by the error
    * the relevant portions of the Alter files
    Note: The cause of this message may manifest itself as different errors at different times. Be aware of the history of errors that occurred before this internal error.

  • Linking user table with system table

    Hello, I'm trying to link a user table with IC table in order to asign many sales person to a customer.
    I've created a new button in the IC form. When clicked a new form is opened to asign sales person to the IC. Now I need to retrieve the records assigned to this IC. How can I do that???
    Regards.
    Angel.

    Hi Angel,
    I would put a matrix in the new form where you could see/asign/delete the sales person.
    Have a look at this post where you can find a great code from Sebastian Danober to fill a matrix from a recordset.
    Another option could be to modify the existing IC form and add a new folder with a matrix where you can manage the sales person.
    Check this other post with code for adding folder to an existing form.
    Regards,
    Ibai Peñ

  • Is any one created Table with in table using adv table with VOs without EOs

    If you have created Advnace table Master-Detail (Table with in table), please let me know the Controller code. I am using below. But getting Nullpointer excveption at innerTable.setAttributeValue(VIEW_LINK_NAME,"ViewLink1VL"); Please help me.
    ===========================
    OAWebBean outerTable = (OAWebBean)webBean.findChildRecursive("region2");
    OAWebBean innerTable = (OAWebBean)webBean.findChildRecursive("region4");
    if (outerTable != null)
    outerTable.setAttributeValue(CHILD_VIEW_ATTRIBUTE_NAME,"FLEX_VALUE_X");
    outerTable.setAttributeValue(VIEW_LINK_NAME,"ViewLink1VL");
    if (innerTable != null)
    innerTable.setAttributeValue(CHILD_VIEW_ATTRIBUTE_NAME,"FLEX_VALUE_X");
    innerTable.setAttributeValue(VIEW_LINK_NAME,"ViewLink1VL");
    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    am.invokeMethod("initGoodsQuery");
    ============================

    My problem was solved when i used ,"ViewLink1VL1" instead of ,"ViewLink1VL" in controller code.
    thanks.
    Gopi.

  • Delete the parent records and child table records at a time

    hi all;
    I am facing the pbm like to delete the all records in child table and corresponding records in parent table at a time. so I want to delete the all the records in child table and corresponding parent records in parent table by using single SQL query. plz help me
    Thanks in advance

    You want to use one single SQL statement to delete the child records in a table and the corresponding master records in the master table??
    That's not quite possible with a single SQL, of course unless you are talking about Oracle Forms, where you have a relation and set the delete behavior to Cascading, like said in the above posts.
    Tony

  • How to check that my table is parent table or child table before trucating

    Hi:
    say i wanted to trucate a table .the table might be a parent table or might be a child table.if its a child table then there wouldnt be any problems in truncating.
    if its a parent table the i believe i would have to diable all the foreign key constraints from the child table referring to the parent table ..my question is
    1. i have a table say ABC. before truncating how do i find out if table ABC is a parent table or not?
    2.lets assume i tried to truncate the table ABC and i got the error saying that disable the foreign keys on the child table referring to the parent table ABC.
    in my schema there are say 50 tables.out of which there might be 10 odd child tables referring to my parent table ABC.
    so my question here would be how do i specifically find out these 10child tables referring to the Parent table ABC so that i can disable the foreign keys on the child tables.
    Thanks 4 ur time in reading this and hopefully i think u wld give me a solution!!

    Hi,
    Try this SQL below:
    select r.owner, r.table_name
    from user_constraints r, user_constraints o
    where r.r_owner = o.owner and r.r_constraint_name = o.constraint_name
    and o.constraint_type in ('P','U') and r.constraint_type = 'R'
    and o.table_name = 'ABC';Cheers

  • Sort a table with two columns based on the first

    I have a powershell table with the columns 'Used Perc' and 'ID'.
    This was formed from the following 
    $a = @{Expression={[System.Math]::Round(($_.nUsed_Avg/$_.nSize)*100,1)};Label="Used Perc";width=25}, @{Expression={$_.nStatisticalDiskIdentificationID};Label="ID";width=15}
    $GLOBAL:CSV2 = Import-CSV $STATDISKOUT | Format-Table $a
    Before this, the file $STATDISKOUT had the columns 'nUsed_Avg', 'nSize', and 'nStatisticalIdentificationID'.
    My question is, how would I sort the new table based on 'Used Perc' but keeping the corresponding 'ID' column lined up to the right value?

    We use a select statement to reorder columns and recalculate,  The formatters just go at the end to adjust the display.
    Import-Csv <file> | select <column order format> | Format-Table
    or you can do it in the table:
    Import-Csv <file | Format-Table -Properties ,f1.,f2.,,f3....Here is how to inset a sort inline:
    $a=@{
    L='ID';
    E={$_.nStatisticalDiskIdentificationID};
    L='Used Perc';
    E={[System.Math]::Round(($_.nUsed_Avg/$_.nSize)*100,1)}
    Import-CSV $STATDISKOUT | Select $a | Sort 'Used Perc' | Format-Table -Auto
    ¯\_(ツ)_/¯

  • Join EQUI table with other table so as get address detail.

    Hi All,
    Can any one help me in the following case :
    I have to pass Equipment No. EQUNR on the selection screen and get Address detail (city, region, state, country, zipcode )
    now I am getting all this address related field in KNA1 table. Also I am able to join this two table with
    KNA1-KUNNR join EQUI-KUNDE as common field.
    Turning point
    when I am passing test data of Equipment No. EQUNR 60099204 I am not getting the address detail,
    because after passing EQUNR I am not getting KUNNR.
    So can any one please help me in joining EQUI table to some other table with field name so that I can get the address detail.
    Thanks

    Hi,
    The join between the table EQUI-kunde  join  KNA1-kunnr is ok but it not working for every value.
    Example :-
    In EQUI table when we pass  Equnr - 60099204 we need to get some value in KUNDE field, then only it will join to KNA1 table. But this is not happening, I am not getting value for KUNDE, hence join is not performing.
    So I need some other solution so that when we pass EQunr we can get the address details
    one thing more equnr  60099204 is having address detail, if we'll check IE03 (transaction by clicking address envelop)
    Thx.

Maybe you are looking for

  • For each loop and modification of a LinkedList

    When going thourhg my LinkedList with a for each loop, I want to do a modification. I just saw that it cast a ConcurrentModification Exception, so it seems I can't do that. How should I do then? I don't want to go through all the list each time an ob

  • Validation of bank details in a business partner

    Hi, We have a requirement where we need to validate the bank details of a business partner. If the details are incomplete then we should not allow the BP to be saved. For this purpose we have used two approaches, namely using the BADI BUPA_BANK_EXPOR

  • PROBLEM IN SUBROUTINE IN SAPSCRIPT!

    CAUFVD IS A STRUCTURE. WHICH HAS ORDER NO 10000427.   IAM USING CAUFVD COZ RESB-AUFNR IN PERFORM DOESNOT GIVE A VALUE IN SAP SCRIPT.   CAUFVD-AUFNR = 10000427   RESB-AUFNR IN SE11 GIVES THE FOLLOWING.   RESB-AUFNR = 000010000427   RESB-RSNUM = 000000

  • I can't  post goods issue for the outbound delivery

    I select the indicator of GI via delivery in transport block via TCODE OPKP and assign the production profile to the work schedule view of the material master.then I create a production order for the material and release it.I do the wm material stagi

  • Add cluster nodes from multiple machines to WebLogic domain in OEM 10.2.0.5

    Hello, I want to monitor a WebLogic domain in Oracle Enterprise Manager 10.2.0.5 with the following layout: - Admin server on machine 1 - managed server, cluster node a on machine 2 - managed server, cluster node b on machine 3 How can I do this? Whe