Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert into table the selected columns from another table [duplicate]

Tags:

sql

insert

What query would insert the selected columns, for a desired value, from a table into another table?

Before Query

table1=>Colums(A,B,C)
  row1(a,b,1)
  row2(c,d,0)
  row3(e,f,1)

table2=>Columns(id,A,B)

After Query

table1 is unchanged.

table2(id,A,B)
  row1(id,a,b)
  row2(id,e,f)

I need to insert in table2 all the rows from table1 where 'C=1', C may equal 1 in multiple records.

like image 697
Maxim Alexandru Avatar asked Dec 19 '25 04:12

Maxim Alexandru


1 Answers

INSERT INTO TABLE2(A,B,C)
SELECT A,B,C
FROM TABLE1
WHERE C = 1
like image 57
T McKeown Avatar answered Dec 20 '25 19:12

T McKeown



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!