Reputation: 548
in Microsoft SQL, when UNION ALL, if the second table doesn't have table1's column, I can use NULL AS.
Sample code:
select a.Key, a.amount from tableA a
UNION ALL
select b.key, NULL AS 'amount' from tableB b
but how to the same NULL AS in Amazon Redshift SQL?
I have a syntax error at or near "'amount'"
Upvotes: 0
Views: 1931
Reputation: 1269483
Do not use single quotes for column aliases.
The following should work in almost any database (although key
may need to be escaped):
select a.Key, a.amount from tableA a
union all
select b.key, NULL AS amount from tableB b;
In fact, the alias is unnecessary in the second query, so you can write:
select a.Key, a.amount from tableA a
union all
select b.key, NULL from tableB b;
Upvotes: 2