Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL - Selecting rows with null columns

How can I select any row that contains empty or null column?

I'm trying to run a check on my table, in which I want to see if any of my rows contain a column that doesn't hold a value..

example table: demo

+----+------+------+
| ID | col1 | col2 |
+----+------+------+
| 1  | VAL1 | Val2 |
| 2  | NULL | Val2 |
| 3  | VAL1 | NULL |
+----+------+------+

I want the query to return rows 2-3 , noting that I have many columns in actual table so I don't want to include it in the query with 'where or'.

can it be done with mysql?

like image 373
Zalaboza Avatar asked Jan 01 '13 16:01

Zalaboza


1 Answers

select * from tablename where col1 is NULL or col2 is NULL

Result

 ID | col1  | col2
 ------------------     
 2  | NULL  | Val2     
 3  | VAL1  | NULL
like image 135
Ravi Avatar answered Sep 28 '22 02:09

Ravi