2012-11-03 98 views
0
DEV|MUL 
xyz|null 
null|abc 
123|456 

我希望得到一個列的值,其中另一種是空或得到明確一列如果兩者都具有從MySQL值選擇科拉姆如果已經選擇了其他科拉姆爲空

+0

看看@ http://stackoverflow.com/questions/3952406/select-column-value-if-not-null-else-use-another-column-value 使用IFNULL(b,a)。 –

回答

1

您可以使用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 
0
SELECT IFNULL(DEV, MUL) AS VALUE from table table1; 

這將返回DEV列值,如果它是not null否則返回MUL列值。

+0

它的no工作,它的返回空值再次 – freakk69

+0

我認爲它只是在第一列中嘗試並返回其中的值 – freakk69

+0

@ freakk69您確定您的示例中顯示的第二列中有價值嗎? –

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