How to combine two similar tables by result

I have two tables with similar columns. I would just like to select both tables, one after the other, so if I have the rows "x" in table1 and "y" in table2, I would get the rows "x + y".

+3
source share
4 answers

For this you would use UNION [ALL]. Tables should not have the same column names, but you need to select the same number of columns from each, and the corresponding columns must be compatible data types

SELECT col1,col2,col3 FROM table1 
UNION ALL
SELECT col1,col2,col3 FROM table2

UNION ALLit is preferable UNIONwhere there is a choice, since it can avoid the sort operation in order to get rid of duplicates.

+6
source

, , By. SQL, .

SELECT Col1, Col2, Col3
FROM   Table1
UNION
SELECT Col1, Col2, Col3
FROM   Table2
ORDER BY Col1

, ORDER GROUP BY UNION.

+4
select col1,col2,col3 from table1
union
select col1,col2,col3 from table2
+2
source

Look at Union .

+1
source

Source: https://habr.com/ru/post/1760131/


All Articles