You are getting an error because it is invalid SQL syntax. Syntax UNION ALL:
SELECT <column1>
FROM <table1>
UNION ALL
SELECT <column1>
FROM <table2>
You cannot reference columns from any query, as you are trying to do. If you want to reference, then you will want to use something like this:
select *
from
(
select some_table1.some_column1, some_table1.some_column2
FROM some_table1
UNION ALL
select some_table2.some_column1, some_table2.some_column2
FROM some_table2
) t1
INNER JOIN some_table3
ON some_table3.some_column1 = t1.some_column1
Taryn source
share