Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL Null Empty IsSet

Tags:

mysql

There is a field called image_src in my table. I would like to get something like a boolean value of 1 if the field contains something ( not null or empty ) else 0 other wise. So is there any function to do that? In PHP we have isset()

Something like :

Select isset(image_src) from table
like image 575
Imran Omar Bukhsh Avatar asked Feb 23 '23 15:02

Imran Omar Bukhsh


2 Answers

Take a look here:

SELECT if(image_src is null OR image_src = '', 0, 1) FROM table

This line will check if the field is null or empty.

like image 131
Aurelio De Rosa Avatar answered Mar 06 '23 05:03

Aurelio De Rosa


MySQL has the isnull function.

like image 28
michael667 Avatar answered Mar 06 '23 05:03

michael667