This is similar to the code I use:
SELECT id, col1 FROM table1
UNION ALL
SELECT id, col2 FROM table2
UNION ALL
SELECT id, col3 FROM table3
...
For example col2 in table2 does not exist, how to make this query work and not to query for columns that do not exist?
>Solution :
Using NULL or any other value and alias it to match column list defintion:
SELECT id, col1 FROM table1
UNION ALL
SELECT id, NULL AS col2 FROM table2
UNION ALL
SELECT id, col3 FROM table3