Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert into a table data and select from another table?

I want to do something like this:

My tb_b:
---------------
   B   |   C     // Columns
---------------
  'y'  |  'z'    // row
---------------

EX: INSERT INTO tb_a(a,b,c) VALUES ('x',SELECT * from tb_b)

I want this result:

My tb_a:
-----------------
 A  |   B   |   C     // Columns
-----------------
'x' |  'y'  |  'z'    // row
-----------------

How to Insert into table a data and selected rows from tb_b?

like image 914
Filipe Tagliacozzi Avatar asked Apr 28 '26 17:04

Filipe Tagliacozzi


1 Answers

INSERT INTO tb_a (a, b, c)
SELECT 'x', tb_b.B, tb_b.C FROM tb_b
like image 166
Explosion Pills Avatar answered Apr 30 '26 06:04

Explosion Pills