mysql CASE WHEN statment for NOT NULL

Subject:

I needed to retrieve information if the user password was set or not

SELECT id, username, CASE WHEN password IS NOT NULL THEN 1 END AS password, firstname, lastname, created, modified, active, try FROM users;

provided info as for passowrd as 1 and if NULL, provided the default entry

you could simply write out and if / else type with CASE WHEN and IS NOT NULL, THEN 

SELECT id, username, CASE WHEN password IS NOT NULL THEN 1 ELSE 0 END AS password, firstname, lastname, created, modified, active, try FROM users;

mysql work with THEN and ELSE

2016-10-21 17:56:07gstlouis

reference http://stackoverflow.com/questions/9387839/mysql-if-not-null-then-display-1-else-display-0

gstlouis
vote
2016-10-21 17:56:26