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
  • 59,113
  • 10
  • 31
  • 55
leebongee
  • 103
  • 1
  • 10

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,284
  • 4
  • 28
  • 42