Insert values from another table

Hello I have a table:

T1
---
ID
user

and another table:
T2
---
intellectual property
Mac

So I modified T1:
ALTER table T1 add ip number (20);
ALTER table T1 add mac number (20);

So I have:
T1
---
ID
user
intellectual property
Mac

T1 and T2 are the same number of lines.

Now, I want to insert the values of IP and mac of T2 in the fields ip address and mac of T1.
IP and mac of T2 fields can be "not null".

How can I do?

Thanks in advance

and what do you think about something like this:

UPDATE t1
   SET t1.mac =
       (SELECT t2.mac FROM t2 WHERE t2.id = t1.id),
       t1.ip =
       (SELECT t2.ip FROM t2 WHERE t2.id = t1.id)

Give it a shot... validate the results before stolen.

HTH,
Thierry

Tags: Database

Similar Questions

  • How can I insert data from another table into a table containing a timestamp column

    How you insert data from another table in a table if the target table contains a timestamp column. I tried to set the default value of GETDATE() column in the target table, but it does not work.


    I use MS SQL

    Sorry, I managed to get around this by inserting null as the value

  • How can I update this table with values from another table?

    Hello

    I have a table 'governed '. I want to replace the values in the column "regies.agent" by the value of the column "regies_personnes.id."
    As you can see the tables have a column of common values. IE regies.agent = regies_personnes.nom

    Table 'governed ':
    Insert into 'authorities' (AGENT) values ('Humberdot Alain");
    Insert into 'authorities' (AGENT) values ("Danard Patrick");

    Table 'regies_personnes ':
    Insert into REGIES_PERSONNES (NAME, ID) values ("Humberdot Alain", 1);
    Insert into REGIES_PERSONNES (NAME, ID) values ("Danard Patrick", 2);

    Before having it
    SQL > select agent of authorities;
    Humberdot Alain
    Patrick Danard

    After the update, the result should be
    SQL > select agent of authorities;
    1
    2

    Thank you for your kind reply.

    You can

    update regies r set agent = (select id from regies_persones p where r.agent = p.nom)
      where exists (select id from regies_persones p where r.agent = p.nom)
    
  • Update of an array of values from another table

    Hi here is my requirement. Please help on this

    I have a table_a

    EmpID pri_location alt_location months of the year

    123                                         2012  Oct
    123                                         2013  Sep
    123                                         2013  Sep
    124                                         2013  Sep
    124                                              2013  Oct
    125                                          2013  Sep

    Another table_b

    EmpID pri_location alt_location

    124         NY                      LA

    125         LA                      NY

    123         NJ                      DC

    I need update statement where my table_a should be updated as below for 2013, only Ms

    EmpID pri_location alt_location months of the year

    123                                              2012  Oct
    NJ 123 DC 2013 Sep
    NJ 123 DC 2013 Sep
    124 NY 2013 Ms
    124                                              2013  Oct
    125. THE NY 2013 Sep

    I make this request, but it is not updated as required

    upgrading from table_a a set (pri_location, alt_location) = (select pri_location, alt_location from table_b b where the b.empid = a.empid and a.year = 2013 and a.month = Sep)

    Please help on this

    Thank you

    upgrading from table_a a set (pri_location, alt_location) = (select pri_location, alt_location from table_b b where b.empid = a.empid) where a.year = 2013 and a.month = Sep

    Try this and after back if it works!

    Kind regards

    Hrvoje

  • I'm trying to get a default value from another table. but!!!!!!!!!!!!!!!

    Here is the code

    {} public void setUnitId (numeric value)

    setAttributeInternal (UNITID, value);

    ProductImpl proImp = (ProductImpl) getProduct ();

    setUnitPrice (proImp.getProdPrice ());

    }

    He tells me that it cannot find a getProduct method if it is used to retrieve an instance of the EO product

    I use Jdeveloper 12 c and 12 c DB

    Thank U My Friend it works. There was no relationship between the tables, and after it is created, it works fine.

  • Procedure with the DML statements that insert values from 1 to 100 in only one table and it is matching word equivalent in the other

    Can someone help me create a procedure with the DML statements that insert values from 1 to 100 in a table "abc" and the procedure must connect the numbers into words in another table "xyz" without doing a commit explicitly. "."

    Currently on trial...

    SQL > create table abc (num number);

    Table created.

    SQL > create table xyz (num varchar2 (100));

    Table created.

    SQL > ed
    A written file afiedt.buf

    1. insert all
    2 values of 1 = 1 then in abc (num) (l)
    3 when the values of 1 = 1 then in xyz (num) (to_char (to_date(l,'j'), 'jsp'))
    4 * Select the level from dual connect by level<=>
    SQL > /.

    200 rows created.

    And the result...

    SQL > select * from abc;

    NUM
    ----------
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    ..
    ..
    ..
    98
    99
    100

    100 selected lines.

    SQL > select * from xyz;

    NUM
    ----------------------------------------------------------------------------------------------------
    one
    two
    three
    four
    five
    six
    seven
    eight
    nine
    ten
    Eleven
    twelve
    ..
    ..
    ..
    98
    Nineteen eighty
    Cent

    100 selected lines.

  • Inserting data from one table to another table

    Hello

    I have the following SQL where I am updating a table by adding new data from another table, but without success.

    INSERT INTO
    () TOP_PROSPECTS
    COMMON_ID
    DATE_ADDED
    REVIEW_RANK
    EVAL_DATE
    PM_ASSIGN
    WHY_NOTES)
    SELECT
    t.COMMON_ID
    t.DATE_ADDED
    t.REVIEW_RANK
    t.EVAL_DATE
    t.PM_ASSIGN
    t.WHY_NOTES
    Of
    TEMP_IVAN_MARY t
    WHERE
    COMMON_ID <>t.COMMON_ID

    Any suggestions?

    Thank you.

    Published by: user13822709 on August 14, 2012 09:14

    Published by: user13822709 on August 14, 2012 09:15

    Is that what you're trying to do with the insert. I think there may be a sign {noformat}<{noformat}{noformat}>{noformat} missing in the where clause. This site eat those, so you need to use the equivalent! = post here.

    If I'm wrong about the missing trader, then it looks like you want to insert rows in temp_ivan_mary that are not already in top_prospects. If Yes, then you need something like:

    insert into top_prospects
       (common_id, date_added, review_rank, eval_date, pm_assign,
        why_notes)
    select t.common_id, t.date_added, t.review_rank, t.eval_date,
           t.pm_assign, t.why_notes
    from temp_ivan_mary t
    where t.common_id not in (select common_id from top_prospects
                              where common_id is not null)
    

    Function index and data available volumnes etc. then a mergr can be more effective. Something like:

    merge into top_prospects p
       using (select common_id, date_added, review_rank, eval_date,
                     pm_assign, why_notes
              from temp_ivan_mary) t
       on (p.common_id = t.common_id)
       when not matched then
          insert (common_id, date_added, review_rank, eval_date, pm_assign,
                  why_notes)
          values (t.common_id, t.date_added, t.review_rank, t.eval_date,
                  t.pm_assign, t.why_notes)
    from temp_ivan_mary t
    

    John

  • Populating one table from another table

    Hi Forum...

    I'm trying to populate a table from another table using CFQUERY... I have no problem with the selection of data from the original table, but need help to get the data into the new table. I use MX 6.1 and access as the database server.
    The two arrays have domain names identical to the same place, and I don't want to have to code all the column names in the selection and insert command. for example

    < cfquery name = "GetData" datasource = 'somename' >
    SELECT * FROM AssetTable1 WHERE BarCode = "123456".
    < / cfquery >

    < cfloop query = "GetData" >
    < cfquery name = "InsData" datasource = 'somename' >
    INSERT INTO AssetTable2 (xxxx...)
    VALUES ("#xxxx... #'")
    < / cfquery >
    < / cfloop >

    I hope this makes sense

    Thanks in advance

    Dave

    If your tables are identical structures and their columns are of the same type and position, and both tables are in the same database, then put everything in a single query.


    INSERT INTO AssetTable2
    SELECT *.
    OF AssetTable1
    WHERE bar code = "123456".

    If the columns were in different positions, then you should be listed explicitly in the INSERT and SELECT the parts, but you get the idea.

    INSERT INTO table1 (col1, col2)
    SELECT col1, col2
    FROM table2
    WHERE all that...

    Phil

  • Gears - error when you try to insert values into a table with multiple columns

    Hello

    I started playing with the gears and SQlLite today and I get an error when I try to insert values into a table with multiple columns.

    I have:

    var db = google.gears.factory.create('beta.database');
        db.open('developerSet');
        db.execute('create table if not exists Developers (DeveloperName text, DeveloperAge int)');
    
        var devName = "Davy"
        var devAge = 32;
    
        try {
            db.execute('insert into Developers values (?, ?)', [devName, devAge]);
            alert('success');
        }
        catch (e) {
            alert(e);
        }
    

    I get the error:

    net.rim.device.api.database.DatabaseException; insert into developers values (?,?): SQL logic error or missing database.

    I use this reference: http://code.google.com/apis/gears/api_database.html

    Everything works if I have only one field as:

    var db = google.gears.factory.create('beta.database');
        db.open('developerSet');
        db.execute('create table if not exists Developers (DeveloperName text)');
    
        var devName = "Davy"
        var devAge = 32;
    
        try {
            db.execute('insert into Developers values (?)', [devName]);
            alert('success');
        }
        catch (e) {
            alert(e);
        }
    

    I use the plug-in Visual Studio 2.0 for 2008 that are running Windows XP SP and Simulator 2.13.0.56

    Thank you

    Davy

    Yes, a SQLite database will persist between battery pulls.  The database is registered either to internal MEM or removable media (not the device memory), depending on which is available on your device.

    In general, its not considered a best practice to remove your table as soon as it is empty and re - create it again when you want to add data.  This adds extra overhead fresh for the final, delete and insert first for a given table.  Instead, define and finalize your drawing before you create your table.  Once created, review the static schema.

    That being said, for development purposes, it may be easier to provide an easy way to drop your tables while you develop your schema.

    See you soon,.

    Adam

  • table name not valid error when inserting values into a table

    I use the following statement to insert values into a table:

    curs. Execute ("INSERT INTO _ * '%s' * _ VALUES ((SELECT MAX (REC_ID) + 1 OF GSAP_MSG_IN), (SELECT MAX (gsap_msg_id) + 1 OF GSAP_MSG_IN), 'SHELLSAP', sysdate, '%s', EMPTY_BLOB(), 1, SYSDATE, EMPTY_BLOB (), SYSDATE)" %(*table_name*,file_extension)) ")

    whence table_name the following statement

    table_name = ' config.staging_db_tablesNames ['in_msgs]

    as I created a configuration file for all parameters that can change. The value of the table in the audit using a print command is correctly, but when put in the query above to run the insert statement gives an error. The following is the summary of comprehensive performance where you can see the table name as

    $ python gsapscnr.py
    Vote for the data files in/home/mh/inbox /...

    GSAP_MSG_IN
    Traceback (most recent call changed):
    File "gsapscnr.py", line 147, in it?
    poll_for_data()
    File "gsapscnr.py", line 86, in poll_for_data
    Sorter = load_details_first)
    File "gsapscnr.py", line 42, survey
    curs. Execute ("INSERT INTO '%s' VALUES ((SELECT MAX (REC_ID) + 1 OF GSAP_MSG_IN), (SELECT MAX (gsap_msg_id) + 1 OF GSAP_MSG_IN), 'SHELLSAP', sysdate, '%s', EMPTY_BLOB(), 1, SYSDATE, EMPTY_BLOB (), SYSDATE)" %(table_name,file_extension)) ")
    cx_Oracle.DatabaseError: ORA-00903: invalid table name

    Can anyone help with this problem please. I'm passing the value of the table in a bad way. Also if anyone can suggest a good tutorial for paythong programming using cx_Oracle.

    Concerning

    Print the SQL string that you establish, cut and paste it this output in SQL * more and see if it runs. This may show you that you should remove the single quotes around the name of the table %s in the Python file.

  • Create a new table from another table which are ussing a stored procedure

    Hello

    I want to know if it is posibble to create a new table from another table which are ussing a stored procedure. This new table is created from another table that exists in the DB.
    (in the following code the table tbl1 exist in the schema of the DB, but temp_tbl1 does not exist, it must be created by the procedure)

    create or replace procedute temp is
    temp_tbl1 tbl1% TYPE; the temp_tbl1 will have the same type of tbl1
    Start
    create the table temp_tbl1 as (select * from tbl1);
    time of the end;
    \


    Thank you very much

    Yes, it is possible to create a table using a procedure.
    Do everything that use dynamic SQL is

    Try this:

    ==================================================
    create or replace PROCEDURE Create Table as
    BEGIN
    EXECUTE IMMEDIATE ' CREATE TABLE testtable in select * from testingtable';
    END createtable;
    ==================================================

    Kind regards
    Ankur

  • How to insert duplicate values in another table.

    angle of attack!
    I created two tables a and b

    create table one
    (key primary code number);

    create table b
    (code number,
    DAT date);

    insert into the table of a (code)
    values (1234);
    insert into the table of a (code)
    values (1235);
    commit;
    Select * from a;
    one
    -----
    1234
    1235
    -----
    insert into the table of a (code)
    values (1234);
    commit;
    ERROR on line 1:
    ORA-00001: unique constraint (GMS. SYS_C0030897) violated

    {color: #ff0000} * I need, when the user inserts duplicate data, must be inserted into another table b.* {color}

    How can I do in forms 6i? Help, please. Thanks in advance.

    Hello

    What is the relationship with the forms?

    Anyway, you can create a trigger on table A that intercepts the error in an exception block, and then create a new row in table B.
    If the error comes from a forms based block, intercept the error in a trigger insert.

    François

  • The default value based on the field from another table to a custom object

    I'm trying to set the default value to a field in the custom object to the value of a field of account. I tried the syntax 50 ways different and just don't get the case. The label for the account field displays the form of s/n, the integration of the tag is ltDBA_ACCT and it appears in the fx reports area as Account.Text_22.

    The field of custom object that I am triying update is also called s/n, which was originally the required field 'NAME '. The name of the table, account, should it be included? Do I need a function to the field?

    I've updated the external ID using the line with syntex < ID > ID (at least higher ID) so I know that it is possible to define a default value, but s / < n >, < ltDBA_ACCT >, 'account '. "" S/n "and so on are simply not working.

    If anyone knows how to get into what I would be really grateful for the help.

    OK, so if you default a field to the value of another object, you must use the JoinFieldValue function. I think you understand that, based on your original post, but I want to be sure you do.

    Then this won't work by default if the folder is created from the object that you want to join the because a default works in record creation and the ID must be available so that it works correctly. It will not work if you choose the record of the related object after that registration of the custom object is created. You can set the default after, but that does not meet your requirements.

    The syntax of the default are the following: JoinFieldValue (ref_record_type, foreign_key, field_name).

    In your case, ref_record_type is '', foreign_key is [] and field_name is ''. The best way is to determine what is the name of the field to create a new workflow for the account and use the Workflow Rule Condition expression builder to choose your field ("DBA") in the list. The value returned by the expression builder must be placed in the field_name variable in the function JoinFieldValue (minus the parentheses and quotes).

    Give it a shot and let me know how you do.
    Thom

  • Insert data from one table to another

    I have two tables SALES_MASTER and SALESMAN_MASTER which is described below.

    SQL > desc SALES_MASTER;
    Name Null? Type
    ----------------------------------------- -------- ----------------------------
    NO VARCHAR2 (6)
    NAME VARCHAR2 (20)
    PIN NUMBER (8)
    CITY VARCHAR2 (20)
    VARCHAR2 (20) STATE



    SQL > desc SALESMAN_MASTER;
    Name Null? Type
    ----------------------------------------- -------- -----------------------
    SALESMANNO VARCHAR2 (6)
    SALESMANNAME VARCHAR2 (20)
    ADDRESS1 VARCHAR2 (30)
    ADDRESS2 VARCHAR2 (30)
    CITY VARCHAR2 (20)
    PIN NUMBER (8)
    VARCHAR2 (20) STATE
    SALAMT NUMBER (8.2)
    TGTTOGET NUMBER (6.2)
    YTDSALES NUMBER (6.2)
    REMARKS VARCHAR2 (60)

    I want to insert data from SALESMAN_MASTER (2nnd table) to SALES_MASTER(first table). I want to insert only two columns NO, NAME and PIN code. All of these columns are compatible. I tried this command. But it's not working. Help me.

    SQL > insert into SALES_MASTER
    2 (NO., NAME, PIN CODE)
    3 values
    4. Select SALESMANNO, SALESMANNAME, PIN code
    5 SALESMAN_MASTER;
    Select SALESMANNO, SALESMANNAME, PIN code
    *
    ERROR on line 4:
    ORA-00936: lack of expression
    INSERT INTO SALES_MASTER
       ( NO
       , Name
       , PINCODE )
       SELECT SALESMANNO
            , SALESMANNAME
            , PINCODE
         FROM SALESMAN_MASTER;
    

    Kind regards
    Christian Balz

  • Insert records from one table to another table

    Hello

    I want to insert all records in table 1 which are not in table 2 in table2

    o/p
    Insert into table2
    Select * from table1
    where a.id! = b.id;

    Please let me know is there any way I can complete reviews
    insert
      into table2
      select  *
        from  table1
        where id not in (
                         select  id
                           from  table2
                        );
    

    SY.

Maybe you are looking for