Home > Mobile >  How to select parameters from different tables in one column sql?
How to select parameters from different tables in one column sql?

Time:02-16

I have two tables with name of countries. I need to do select, which will show first countries names from first table and then from second table.

table1: USA Germany

table2: Spain Ukraine

Expected result from select:

USA
Germany
Spain
Ukraine

CodePudding user response:

SELECT * FROM table1
UNION ALL
SELECT * FROM table2

CodePudding user response:

select Country from table1
union
select Country from table2

CodePudding user response:

you can try like below

with cte as(
select country_name,
row_number()over(order by country_name) as rn  from table1
union all
select country_name,-1 from table2
) select country_name from cte order by rn desc

CodePudding user response:

If you have a common field you can use the following:

SELECT * FROM table1 OUTER JOIN table2 ON table1.ID=table.ID;
  • Related