Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading