I don't know if this is possible with mySQL but I want to return a true|false value if a column is not null.
Suppose you have this data:
------------------------------------
| id | path | tags |
------------------------------------
| 1 | img-001.jpg | cats,animals |
| 2 | img-002.jpg | baby,family,boy |
| 3 | img-003.jpg | null |
| 4 | img-004.jpg | cars |
------------------------------------
I'd like to SELECT to get a results array something like:
{id:1, path:img-001.jpg, hasTag: true},
{id:2, path:img-002.jpg, hasTag: true},
{id:3, path:img-003.jpg, hasTag: false},
{id:4, path:img-004.jpg, hasTag: true}
Can mySQL do that for me without needing the application to iterate over the data?
CASEsyntax:SELECT id, path, CASE WHEN tags IS NOT NULL THEN true ELSE false END AS hasTag. [Documentation]CASE WHEN ... END CASE. Official documentation here.