chirayu patil
chirayu patil

Reputation: 15

how to display two column values without their null values in SQL?

I have two columns let's say A and B , both columns contains some null values.

I want to display both column values excluding their null values.

Any suggestion or help would be very helpful.

Upvotes: 0

Views: 474

Answers (4)

Arnav Joshi
Arnav Joshi

Reputation: 96

If you want results with no null values then use

select a, b from your_table where a is not null and b is not null

If you want results which can have one column null but not both

select a, b from your_table where a is not null or b is not null

Upvotes: 0

HaveNoDisplayName
HaveNoDisplayName

Reputation: 8517

You can use ISNULL with column name, to replace Empty value if column contains NULL

SAMPLE SQL FIDDLE

SELECT ISNULL(A,'') A, ISNULL(B,'') B
From TableName

If you dont want to show null records then Use in Where clause IS NULL NULL

SELECT A,B
From TableName
Where A IS NOT NULL AND B IS NOT NULL

Upvotes: 1

mg_dev
mg_dev

Reputation: 1403

Try this:

SELECT A, B FROM MYTABLE WHERE A IS NOT NULL AND B IS NOT NULL

Feel free to comment in case you need few more logic in this.

Upvotes: 1

NendoTaka
NendoTaka

Reputation: 1224

You could add Where A IS NOT NULL to your query to get rid of all of the null values in column A. You will need to modify this a bit to work with what you want.

Upvotes: 1

Related Questions