Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether column value is NULL or having DEFAULT value in Mysql

Tags:

sql

mysql

I want to fetch records for column value not equal to null and column value not equal to default value. I know that we can use

SELECT * FROM table WHERE column_name is NOT NULL AND column_name != 'some_default_value';

but what if some one in future changes this some_default_value in table? Is there a flexible solution?

like image 247
Shreekrishna Bellubbi Avatar asked Oct 30 '22 07:10

Shreekrishna Bellubbi


1 Answers

You can use the DEFAULT function:

SELECT * 
FROM table 
WHERE IFNULL(column_name, DEFAULT(column_name)) <> DEFAULT(column_name);
like image 127
Sebastian Brosch Avatar answered Nov 14 '22 07:11

Sebastian Brosch