'How to use UNION ALL without null values for column count mismatch
I have below tables
select id,name from t1
id name
1 A
2 B
select id,name,sal from t2
id name sal
1 C 1000
2 D 2000
select id,name,Null as sal from t1
UNION ALL
select id,name,sal from t2
id name sal
1 A null
2 B null
1 C 1000
2 D 2000
But I need like this without null can we use union all option
id name sal
1 A
2 B
1 C 1000
2 D 2000
Solution 1:[1]
One way you can try to add an empty string for T1, let sal's type as a string.
SELECT id,name,'' sal
FROM T1
UNION ALL
SELECT id,name,sal::TEXT
FROM T2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | D-Shih |
