'Eliminating NULL Values in SQL
I have a complex subquery within a query giving me this:
Col 1 | Col 2 |
---|---|
value1 | NULL |
NULL | value2 |
value3 | NULL |
NULL | value4 |
value5 | value5 |
But instead, I need this output:
Col 1 | Col 2 |
---|---|
value1 | value2 |
value3 | value4 |
value5 | value5 |
the condition Col1 IS NOT NULL OR Col2 IS NOT NULL
doesn't work obviously. Is there any other way to filter null values out or does the previous query have to change? I didn't want to include the wholesome script as it is not very relevant to this filtering part of the query.
I appreciate your help.
Solution 1:[1]
I don't know what is your case and why you want to do this, but your question seems weird
But as far as I could understand below query might work as your expectation, I used some extra columns
Replace your sub query at particular place
select col1,Col2 from (
(select ROW_NUMBER()over(order by a)index1,* from
(select 'a'a,Col1 from (YOUR SUB QUERY) t1 where col1 is not null)a)t1 full outer join
(select ROW_NUMBER()over(order by a)index1,* from
(select 'a'a,Col2 from (YOUR SUB QUERY) t1 where col2 is not null)b)t2 on t1.index1=t2.index1)
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 | MANthan N Patel |