freakk69
freakk69

Reputation: 161

select a column if the other column already selected is null

DEV|MUL
xyz|null
null|abc
123|456

I want to get the value of a column where the other one is null or get specifically one column if both have values from mysql

Upvotes: 0

Views: 159

Answers (3)

Vikram Jain
Vikram Jain

Reputation: 5588

select * from tablename where (columnname is null)
and
select * from tablename where (columnname1 is null) and (columnname2 is null)

Upvotes: 0

Yogendra Singh
Yogendra Singh

Reputation: 34367

SELECT IFNULL(DEV, MUL) AS VALUE from table table1; 

This will return DEV column value if it is not null otherwise return MUL column value.

Upvotes: 0

codingbiz
codingbiz

Reputation: 26386

You can use IFNULL

SELECT IFNULL(DEV, MUL) as Col FROM myTable  -- MySql

SELECT ISNULL(DEV, MUL) as Col FROM myTable  -- SQL Server

SELECT NVL(DEV, MUL) as Col FROM myTable  -- Oracle

Upvotes: 1

Related Questions