Insert Matching Records from Lookup Table to Main Table

First off, I want to say many thanks for all the help that I've been provided on here with my other posts. I really feel as though my SQL knowledge is much better than it was even a few short weeks ago, largely in part to this forum.
I ran into a snag, which I'm hoping someone can provide me some guidance on. I have 2 tables an import table and a lookup table. What I need to have happen is anytime there are matches between the "Types" in the 2 tables, I need a single instance
of the "Type" and all corresponding fields from the lookup table appended to the import table. There will only be a single instance of each type in the "Lookup" table. Below is an example of how the data might look and the results that
I would need appended.
tblLookup
Type Name Address City
A Dummy1 DummyAddress No City
B Dummy2 DummyAddress No City
C Dummy3 DummyAddress No City
tblImport
Type Name Address City
A John Maple Miami
A Mary Main Chicago
A Ben Pacific Eugene
B Frank Dove Boston
Data that would be appended to tblImport
Type Name Address City
A Dummy1 DummyAddress No City
B Dummy2 DummyAddress No City
As you can see only a single instance will be inserted even though there may be multiple instances in the import table. This is the part that I'm struggling on. Any assistance would be appreciated.

I'm not really sure how else to explain it. With my example, the join would be on "Type" As you can see, there are 2 matching records between the tables (A and B). I would need a single instance of A and B to be inserted into the import table. 
Below is a SQL statement, which I guess is what you're asking for but it will not do what I need it to do. With the example that I have below, it would insert multiple instances of type "A" into the import table.
INSERT INTO tblImport (Type, Name, Address, City)
Select tblLookup.Type, tblLookup.Name,
tblLookup.Address, tblLookup.City)
From tblLookup
Join tblImport on tblLookup.Type = tblImport.Type

Similar Messages

  • Migrating data from LookUp Table to Main Table without taking extract

    Dear Experts,
    Is there any way if we want to migrate full data from LookUp Table to Main Table in the same repository without taking the extract from MDM DM and not importing it using Import Manager?
    Thanks
    Gaurav Kumar Sharma

    Hi Gaurav,
    Yes there are ways,like you can create port for syndication and use MDIS to import it back but Extraction from DM would be more convenient though.You can also use APIs to syndicate the lookup data and import it back in MDM.
    Can you please detail what you want to achieve?
    Thanks,
    Ravi

  • Insert records from report program into R3 table

    Hi
    I wanted to insert records from report program into R3 table.
    here is my code
    data : itab type standard table of zemp initial size 10 with header line.
    itab-EMPNO = '012'.
    itab-ENAME = 'XXXX'.
    itab-JOB = 'XXXX'.
    APPEND itab.
    insert ztable from table itab.
    but i am getting the following error
    the type of the data base table and work area/internal table "ITAB" are no unicode-converible.
    how can I insert records from report program into R3 table
    should I have to write move corresponding
    pls guide
    thanks
    manian

    Hi,
    itab-EMPNO = '012'.
    itab-ENAME = 'XXXX'.
    itab-JOB = 'XXXX'.
    APPEND itab.
    insert ztable from table itab.
    Do one thing
    Data : itab type table of ztable with header line.
    itab-EMPNO = '012'.
    itab-ENAME = 'XXXX'.
    itab-JOB = 'XXXX'.
    APPEND itab.
    insert ztable from table itab.
    error will resolve, then try to make structure similar to ZTABLE

  • How get all record from master and matching record from detail

    hi master
    sir i have master detail table
    i have many record in master table but some record in detail table how i get
    all record from master and matching record from detail
    such as
    select m.accid,m.title,d.dr,d.cr from master m, detail d where m.accid=d.accid
    this query not work that get only related record i need all record from master
    please give me idea
    thanking you
    aamir

    hi master
    sir i have master detail table
    i have many record in master table but some record in
    detail table how i get
    all record from master and matching record from
    detail
    such as
    select m.accid,m.title,d.dr,d.cr from master m,
    detail d where m.accid=d.accid
    this query not work that get only related record i
    need all record from master
    please give me idea
    thanking you
    aamir
    select m.accid,m.title,d.dr,d.cr
    from master m, detail d
    where m.accid=d.accid (+)The outer join operator (+) will get you all the details from master and any details from the detail if they exist, but the master details will still be got even if there are not details.
    Note: Oracle 10g now supports ANSI standard outer joins as in:
    select m.accid,m.title,d.dr,d.cr
    from master m LEFT OUTER JOIN detail d on m.accid=d.accid

  • Insert multiple records from web dynpro

    Hi,
    How to insert multiple records from web dynpro applications to SAP backend system ?
    Thanks,
    sowmya

    Hi soumya..
       if want to multiple row selected  then save into the Sap back End..
       value node--table.
    Backend value node=table_bapi_input;
       back end internal table --tableback.
    int size=wdcontext.nodeTable().size();
    int lead=wdcontext.nodeTable().getLeadSelection();
    table_bapi_input in=new table_bapi_input();
    wdcontext.nodetable_bapi_input().bind(in);
       for(int i=size-1;i>0;i--){
    tableback set=new tableback()
    if(lead==i || wdcontext.nodeTable().ismultiSelection(i)){
    set.setName(wdContext.nodeTable().getTableElementAt(i).getName();
    in.addZc_input(set);
    wdContext.currenttable_bapi_inputElement().modelobject().excute();
    wdContext.nodeOutput().invalidate();
    thanks
    jati

  • How can  distribute 5 lakhs records from sap R/3 setup tables ?

    How can  distribute 5 lakhs records from sap R/3 setup tables in to multiple  requests in sap BI?

    Hello,
    what is "lakhs" ?
    Please use plain English words on a world wide forum...
    Regards,
    Olivier

  • How do I extract matching records from two tables?

    I'm trying to extract client records from our client database to put together a very targeted email campaign. As an example, the result I want is a list of names and email addresses of those clients who have a record in our system, have not had a visit in our clinic in the last year, and live within 200 miles of our clinic. I can capture the first two criteria in one extract, and the second in another. I can then import those as tab delimited data into Numbers. What I then need to do is create a third table that represents ONLY those records that exist in both tables.
    Can someone tell me if this is possible and if so, how to do it?
    I'd be very appreciative of any help, thank you.

    conejo61 wrote:
    I can then import those as tab delimited data into Numbers. What I then need to do is create a third table that represents ONLY those records that exist in both tables.
    You can create a column that generates a serial marker on the table from which you want to transfer the data, making all the names that also appear on the other table. Not that the formula will mark only exact matches.
    Here's a short example:
    Table 1 on the left, is one of the two tables imported from the tab delimited data files. It has other data, but only the names in column A are used to identify records appearing on both tables.
    Table 2 on the right, contains the names and other data (represented by the email addresses in column B), to be transferred to the third table.
    Column C of this table contains the formula that counts off the rows containing names appearing on both tables. The version below is in C2, and is filled down to the end of the column.
    =IF(COUNTIF(Table 1 :: $B,A2)>0,MAX($C$1:C1)+1,"")
    Note that jane Doe is not counted (or transferred) as her name is recorded differently on the two tables.
    Table 3 is the results table. It contains one formula for each column to be transferred from Table 2 to Table 3.
    A2:   =IF((ROW()-1>MAX(Table 2 :: $C)),"",LOOKUP(ROW()-1,Table 2 :: $C,Table 2 :: $A))
    B2:   =IF((ROW()-1>MAX(Table 2 :: $C)),"",LOOKUP(ROW()-1,Table 2 :: $C,Table 2 :: $B))
    Regards,
    Barry
    EDIT: I was working in Numbers '09 when developing this, and got the following warning when I saved a copy as an iWork '08 document:
    Referencing row or column ranges that include header or footer cells isn't supported. The formula references were updated to exclude header and footer cells.
    The formulas in Table 2::C2 references C1. You may have to ensure that Table 2 does not include a header row.
    B.
    EDIT2: A check on the file in Numbers '08 showed no apparent change to the formula, and editing Jane Doe's name on table 1 resulted in her name being added to Table 3.
    Message was edited by: Barry

  • Insertion of records from view into a table

    hello Friends,
    I have a view LGR is build on 12 table,this view has over 1 millon records, now when i run reports based on this view are so much slower, for speeding up reports i create a table LGRT and base all the reports on it, but the problem is that after any chage to the data of the LGR view , I delete all records from LGRT table and reinsert all records from LGR view
    delete from lgrt;
    insert into lgrt
    select *
    from lgr
    friends its a very long procedure what can i do to minimaze the human work.....
    i mean that it should be done automatically.

    Hello,
    It sounds like you could use a materialised view here to speed things up, also it will save you the hassle of deleting records from the temporary table etc as they offer quite a few synchronisation options. Have a look at the documentation here:
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_63a.htm#SQLRF01302
    There a quite a few examples toward the bottom of the page.
    HTH

  • Insert records from user form to multiple tables in same database

    Hi Experts, I need your help. I have a form that has multiple text fields that I need to insert the records to their each respective table. For example: The first name field needs to go the the name table, address goes to a seperate table, phone goes to a seperate table and so on.
    Is this possible to do?
    Thanks Much
    Sham

    The same for ASP, JSP or PHP.  Just the code syntax is different for each language.  Are you using MySQL, Access or ?
    In any case, create the three recordsets on the database and use insert queries.  If you don't know what one is, google insert query and you will see the syntax. 
    Here is a good example out on the web
    http://www.stardeveloper.com/articles/display.html?article=2000032601&page=1
    In your case you would get the values for the inserts from the form data and only need to open the database connection once.
    Good luck.
    Walt
    B & B Photography

  • Some Times Table is inserting Partial record from a view Why?

    The query consists of a simple insert statement where the data is inserted from a view. The issue is that some times only the first retreived record from the select statement are inserted into the table from a view and the rest are ignored when we scheduled in the batch job of EM console. Some times it inserted correctly.
    For Ex.
    INSERT INTO Table_COLL(COL_A, COL_B, COL_C)
    SELECT COL_A, COL_B, COL_C
    FROM COLL_VIEW
    WHERE DATE=TRUNC(SYSDATE);
    COMMIT;
    The select statement retreives 200 records and the insert statement works perfectly as expected when executed in SQL* plus.
    However the issue happens where only one record is inserted when the same query is scheduled in the batch job of the EM console or a procedure is created for the query and the same is scheduled in the EM console as a batch job and Some times it inserted correctly in EM Console.
    Can anyone explain as why this is hapenning? (DB is Oracle 10g& size is 100gb )

    I doubt that there is a bug. I suspect the query runs when you schedule it at a point of time where TRUNC(SYSDATE) gives less rows...
    You could store the COUNT(*) and execution time before you run the INSERT in a LOG table. Any transaction based on two times (runtime and systime) can lead to unexpected results.
    What about something like this:
    INSERT INTO Table_COLL(COL_A, COL_B, COL_C)
    SELECT COL_A, COL_B, COL_C
    FROM COLL_VIEW a
    LEFT JOIN Table_COLL B
    ON (      a.COL_A = b.COL_A
          AND a.COL_B = b.COL_B
          AND a.COL_C = b.COL_C)
    WHERE a.DATE>=TRUNC(SYSDATE)-1
    AND b.COL_A IS NULL;
    COMMIT;

  • Delete matching records from internal table

    I have two internal tables.
    say :
    1)zsd80
    2)i_vbrk
    i want to delete records from i_vbrk which are not in zsd80.
    this is my code. but it shows dump error after executing. please help.
    LOOP AT i_zsd80 INTO zsd80.
                LOOP AT i_konv INTO w_konv FROM w_index.
                  IF w_konv-kschl NE zsd80-kschl.
                    DELETE i_konv FROM w_konv.
                  ENDIF.
                ENDLOOP.
              ENDLOOP.

    Hi,
    Do like this...
    1. Loop at the where u want to delete..
    2. store the sy-index...
    3. read the other table....
    4. if nothing found  in read then delete that index...
    LOOP AT i_vbrk.
      TABIX = SY-TABIX.
      READ TABLE zsd80 WITH KEY .......
      IF SY-SUBRC NE 0.
        DELETE IT_VBRK INDEX TABIX.
      ENDIF.
    ENDLOOP.
    regards
    Sukriti.....
    Edited by: Sukriti Saha on Nov 3, 2008 1:19 PM

  • Insert Value(s) in Lookup Flat Multi-valued Table with Java API

    I've been looking in MDM Java API Library Reference Guide, MDM SP4 API JavaDoc, and SDN Forums for information on how to Insert/Update different values in a field in the Main Table of a given repository that belongs to a Lookup Flat Multi-valued Table using the Java API with no success.
    I also haven't been successful in adding this values in the same way that I'll add a single value, using the MDM Java API, in a single-value Lookup Table (a2iFields.Add(new A2iField(FIELD_CODE,FIELD_VALUE)) for each value I want to add, like for example:
    a2iFields.Add(new A2iField("Country","USA")
    a2iFields.Add(new A2iField("Country","Mexico")
    a2iFields.Add(new A2iField("Country","Germany")
    Can anybody point me to the correct documentation that I need to read to fulfill this task? Or, even better, if someone can post a piece of code, I'll be more thankful.
    Thanks for your help.

    HI,
    little code example, where you add existing lookup values based on there record id:
         int USA = 1;
                        int GERMANY = 2;
                        A2iValueArray countryArray = new A2iValueArray();               
                        countryArray.Add(new Value(USA));
                        countryArray.Add(new Value(GERMANY));
                        A2iFields record = new A2iFields();
                        record.Add(new A2iField("Country", new Value(countryArray)));
    Please reward points if helpful.
    Regards,
    Robert

  • Sql query to bring single record from right side of a table

    hi
    I have two tables as below:
    create table testsh1 ( idd varchar2(10), name varchar2(20));
    create table testsh2 ( idd varchar2(10), balance float );
    insert into testsh1 values('1','abc');
    insert into testsh1 values('2','def');
    insert into testsh1 values('3','ghi');
    insert into testsh1 values('4','jkl');
    insert into testsh1 values('4','jkl');
    insert into testsh1 values('3','ghi');
    insert into testsh2 values('1',500);
    insert into testsh2 values('1',500);
    insert into testsh2 values('3',1000);
    insert into testsh2 values('3',1000);
    insert into testsh2 values('4',1500);
    insert into testsh2 values('4',1500);
    insert into testsh2 values('1',500);
    I am expecting the result below:
    1 abc 500
    2 def NULL
    3 ghi 1000
    3 ghi 1000
    4 jkl 1500
    4 jkl 1500
    That is only records from testsh1 table can come as many times but from testsh2 only we need to bring unique and matching records on column idd.
    Please help
    Thanks

    Hi Shavetha,
    As the testsh2 has duplicates of each record, the DISTINCT of the record has to be record has to be applied.
    Please Try this,
    SELECT IDD, NAME, (SELECT DISTINCT BALANCE
                                  FROM TESTSH2 B
                                 WHERE B.IDD = A.IDD) BALANCE
      FROM TESTSH1 A;Which Outputs:
    IDD     NAME     BALANCE
    1     abc     500
    2     def     
    3     ghi     1000
    4     jkl     1500
    4     jkl     1500
    3     ghi     1000Thanks,
    Shankar

  • Need to insert selected records from PROD into TEST

    I am trying to insert all records (for a specific region only) from production to test.
    I'm a little confused about how the pl/sql would look for this.
    Note that as I insert into the table in test, I also have a key field that is auto incremented by 1 each time.
    The problem that I am having is I need to link two tables in PROD together to determine the region:
    So in test, I want to do something like:
    INSERT INTO ACCOUNT_PRICE
    (select * from ACCOUNT_PRICE@PROD, MARKETER_ACCOUNT@PROD
    where substr(MARKETER_ACCT_NO,1,1) = '3'
    and MARKETER_ACCOUNT_NO = PRICE_ACCOUNT_NO);
    However, i'm not sure if this is correct or if I should be using a BULK insert.
    Note that I cannot just load the whole table as I need to restrict it to only one region of data.
    Any help would be appreciated.
    Sean

    Direct load (BULK) is irrelevant to what you are asking. I would strongly suggest that you read the docs about this feature before considering it for any purpose.
    As to your question what you are asking is unclear and, for reasons known only to you, you did not include a version number.
    So given that I get to invent your version number I have decided you have 10g and therefore you have DataPump so my recommendation is to use
    DataPump to extract and export the records you wish to move.
    http://www.morganslibrary.org/reference/dbms_datapump.html

  • Inserting nested records from XML to DB

    Hi,
    I am facing a problem with inserting nested records in XML to DB. For example, I have this XML:
    <?xml version="1.0" encoding="utf-8" ?>
    <ns0:CutLOTUpdate xmlns:ns0="http://LayoutTracking/v1.0">
    <C>1</C>
    <COMMENTS>Main1</COMMENTS>
    <CUT_DATA>
    <CUT>
    <D>1</D>
    <COMMENTS>2Main1</COMMENTS>
    <IT>
    <E>11</E>
    <COMMENTS>3Det1</COMMENTS>
    </IT>
    <IT>
    <E>12</E>
    <COMMENTS>3Det2</COMMENTS>
    </IT>
    </CUT>
    <CUT>
    <D>2</D>
    <COMMENTS>2Main2</COMMENTS>
    <IT>
    <E>21</E>
    <COMMENTS>3Det1</COMMENTS>
    </IT>
    <IT>
    <E>22</E>
    <COMMENTS>3Det2</COMMENTS>
    </IT>
    </CUT>
    </CUT_DATA>
    </ns0:CutLOTUpdate>
    I would like to insert these data into the following table in a denormalized form:
    CREATE TABLE A (
    C NUMBER,
    D NUMBER,
    E NUMBER,
    C_COMMENTS VARCHAR2(50),
    D_COMMENTS VARCHAR2(50),
    E_COMMENTS VARCHAR2(50))
    I have tried using this procedure:
    CREATE OR REPLACE PROCEDURE insc (Cut_Clob CLOB) AS
    Cut XMLType;
    BEGIN
    /*Converts Cut_Clob parameter into XML */
    Cut := sys.xmltype.createXML(Cut_Clob);
    /*Inserts data from XML to table*/
    INSERT INTO a
    ( C ,
    C_COMMENTS ,
    D ,
    D_COMMENTS ,
    E ,
    E_COMMENTS )
    SELECT DISTINCT
    ExtractVALUE(CUT, '/ns0:CutLOTUpdate/C' , 'xmlns:ns0="http://LayoutTracking/v1.0') C,
    ExtractValue(CUT, '/ns0:CutLOTUpdate/COMMENTS', 'xmlns:ns0="http://LayoutTracking/v1.0') C_COMMENTS,
    ExtractVALUE(value(ct), '/CUT/D') D,
    ExtractValue(value(ct), '/CUT/D_COMMENTS') D_COMMENTS,
    ExtractVALUE(value(it), '/IT/E') E,
    ExtractValue(value(it), '/IT/E_COMMENTS') E_COMMENTS
    FROM TABLE (xmlsequence(extract(CUT,'/ns0:CutLOTUpdate/CUT_DATA/CUT','xmlns:ns0="http://LayoutTracking/v1.0'))) ct,
    TABLE (xmlsequence(extract(CUT,'/ns0:CutLOTUpdate/CUT_DATA/CUT/IT','xmlns:ns0="http://LayoutTracking/v1.0'))) it;
    COMMIT;
    END;
    However, this resulted into a cartesian product.
    Is it possible for me to insert this XML into such table? If yes, can anyone show me how?
    I apologize if this seems trivial to you and I appreciate your time for helping me.
    Thank you,
    Kaye

    Hi,
    I have tried:
    FROM TABLE (xmlsequence(extract(CUT,'/ns0:CutLOTUpdate/CUT_DATA/CUT','xmlns:ns0="http://LayoutTracking/v1.0'))) ct,
    TABLE (xmlsequence(extract(CUT,'/ns0:CutLOTUpdate/CUT_DATA/CUT/IT','xmlns:ns0="http://LayoutTracking/v1.0'))) it;
    This did not work - resulting in Cartesian product.
    I am working with Oracle 10g DB 10.2.0.1.
    If it's not too much, I am hoping that someone could show me a script to parse this XML and actually place it in a denormalized form.
    If you think this is not possible, can you please just point me to an example where the same XML (with nested information) can be inserted into 3 different tables (relational)?
    I have tried searching on different sources, to no avail. I am a beginner on this... I apologize for any inconveniece caused.

Maybe you are looking for