5

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
0

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

3

MySQL has the isnull function.

1 Comment

There is no dedicated function for that. If you want to check both, you should use a CASE expression.
2
SELECT IF(ISNULL(image_src), 0, 1) AS aliased_value FROM table

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.