Home > Software engineering >  Merge two tables in SQL
Merge two tables in SQL

Time:10-11

I have two tables in my database

Table A:

Start_Date    End_date      Ad_name       Amount Spent
2022-09-01   2022-09-30    Facebook -      2.5
2022-09-01   2022-09-30    Facebook -      24.5
2022-09-01   2022-09-30    twitter -        12.5

Table B:

Start_Date    End_date      Ad_name       Amount Spent
2022-08-01   2022-08-30    instagram -      52.5
2022-08-01   2022-08-30    Facebook -      124.5
2022-08-01   2022-08-30    twitter -        30
2022-08-01   2022-08-30    twitter -        60

I want to get to get an output of Table C

Start_Date    End_date      Ad_name       Amount Spent
2022-09-01   2022-09-30    Facebook -      2.5
2022-09-01   2022-09-30    Facebook -      24.5
2022-09-01   2022-09-30    twitter -        12.5
2022-08-01   2022-08-30    instagram -      52.5
2022-08-01   2022-08-30    Facebook -      124.5
2022-08-01   2022-08-30    twitter -        30
2022-08-01   2022-08-30    twitter -        60

Kindly help.

CodePudding user response:

Because your tables have the same structure you ca use a simple UNION:

SELECT * FROM A
UNION ALL
SELECT * FROM B;

sql editor online

CodePudding user response:

I bet you need UNION ALL:

SELECT * FROM A
UNION ALL
SELECT * FROM B
  • Related