SQL Query to insert values โ€‹โ€‹from one table into another

I have 2 tables:

Table a:

RID; Name; LP EF 1 EF 2 EF 3 EF 12 EF 152 

Table B:

 LP 1 2 3 12 152 ... 156 157 180 itd. 

Request something like:

 Insert into TableA(RID, Name, LP) Values ('E', 'F', Select LP from TableB) 

I want to achieve:

 RID; Name; LP EF 1 EF 2 EF 3 EF 12 EF 152 EF 156 EF 157 EF 180 etc. 
+4
source share
4 answers

You're close Try

 INSERT INTO TableA(RID, Name, LP) SELECT 'E', 'F', LP FROM TableB -- Omit this where clause, if duplicate LP are OK WHERE TableB.LP NOT IN (SELECT LP FROM TableA) 
+10
source
 Insert into TableA(RID, Name, LP) Select 'E', 'F', LP from TableB 
+1
source

The โ€œquick and dirtyโ€ solution I came across is:

Insert into TableA(RID, Name, LP) Values ('E', 'F', Select LP from TableB where rowid = 1)

Insert into TableA(RID, Name, LP) Values ('E', 'F', Select LP from TableB where rowid = 2)

...

etc.

0
source

select * in [NEW_TABLE] from [OLD_TABLE]

No need to create a new table. It will be created automatically.

Enjoy.

0
source

Source: https://habr.com/ru/post/1388452/


All Articles