1

I'd a trouble with inserting data from 3 table: A (id, name), B (id, name), C (id, name). They have the same field like that. How can I insert data from 3 tables above into table D (id, name)?

Barbaros Özhan
  • 47,993
  • 9
  • 26
  • 51
leebongee
  • 93
  • 1
  • 8

1 Answers1

4

You could use UNION or UNION ALL

INSERT INTO table_d(id, name)
SELECT id, name
FROM table_a
UNION ALL 
SELECT id, name
FROM table_b
UNION ALL 
SELECT id, name
FROM table_c;   

If you want to remove duplicate rows in 3 tables, change UNION ALL to UNION. Refer information about union vs union all

Pham X. Bach
  • 5,039
  • 2
  • 24
  • 35