0

I have this kind of table:

Column 1 | Column 2 | Column 3 | Column 4
----------------------------------------
Value 1  |  null    | null     | null    
null     |  Value 2 | null     | null    
null     |  null    | Value 3  | null  
null     |  null    | null     | Value 4

I want to eliminate null values. I want it to be like this:

Column 1 | Column 2 | Column 3 | Column 4
----------------------------------------
Value 1  |  Value 2 | Value 3  | Value 4  

Any help will be much appreciated. Thanks.

2
  • What would you expect to happen if there were more than four rows in the table, or if one of the rows had more than one value defined? Commented Oct 1, 2018 at 17:43
  • What have you tried so far..? Not even DELETE FROM table WHERE [Column 1] IS NULL AND [Column Two] IS NULL AND.... you get the picture. Commented Oct 1, 2018 at 17:43

1 Answer 1

3

It seems you want aggregation :

select max(col1), max(col2), max(col3), max(col4)
from table t;

Assuming you have a supportive column if so, then you can do :

select col, max(col1), max(col2), max(col3), max(col4)
from table t
group by col;
Sign up to request clarification or add additional context in comments.

1 Comment

The only time this won't work is if there are more values in any of the columns. At that point, in order to make it work, you will have to have a common column to group by as in the second example above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.