Question
I'm trying to select some integer values in MySQL. Several of the values are zero, which I want to grab as an empty string, and grab the integer values when available.
So I have something like this:
SELECT CASE field WHEN 0 THEN '' ELSE field, [repeat for other fields]
Is there any way to shorten this in the SQL query? Does MySQL support the ternary operator?
Solution
There's IF
select IF(field1=0,'',field1), ...
And if your fields are NULL, there's IFNULL
select IFNULL(field1,'')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow