简体   繁体   中英

How to copy some record from a table to another

I have two tables and I want to copy some records from table1 to table2

Table1: field1,field2,field3,field4
Table2: f1,f2,f3,f4,f5,f6

INSERT INTO Table2 (f1,f2)
SELECT field1,field2 FROM Table1
WHERE Table2.f3=1234;

but I have this error

ORA- 00904: STRING: invalid identifier tips

How can I set a WHERE condition for Table2? I have to insert these records only if f3 from Table2 is equal a certain value

You are looking for the update and you can do it as follows:

UPDATE Table2 
   SET (f1,f2) =  (SELECT field1,field2 
                     FROM Table1 
                    WHERE <JOIN CONDITION BETWEEN TABL1 AND TABLE2>)
 WHERE Table2.f3=1234;

I Assume you need the below based on the structure of your query

 INSERT INTO Table2 
 SELECT field1,field2,f3,f4,f5,f6 FROM Table1,Table2
 WHERE Table2.f3=1234
 and Table2.f3=Table1.field3;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM