showing table after one table in sql

Issue

I have several tables in my DB and all tables have same columns.
for example:

table1

id  name  age  city   
1   Van   18    NY

table2

id  name  age  city  
1   Ben   23    LA

I want to show these tables in my dashboard one after one like

NewTable

id  name  age     city   
1   Van   18      NY              
1   Ben   23      LA

Solution

This is basic sql

Use UNION if you want to get an output free of duplicates (kind of distinct)

Use UNION ALL if you want get an output with all records from all tables.

select id, name, age, city from table1
union -- or union all...
select id, name, age, city from table2

Answered By – James

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published