Reputation: 1853
I need to do something rather strange in MySQL, and I'm hoping to get some ideas on how to go about doing it in a query rather than post-processing the query results.
I have a field in the database that in some cases I need to return the value and in some cases, I don't want the value to be shown. Because of a variety of reasons, I can't simply remove the field from the query when I don't want the value to be shown. I need to obfuscate it - either by blanking it out, or replacing it with # signs, etc.
With dates, I can use DATE_FORMAT to return the date in the desired format. Is there any kind of function I can do in MySQL that will hide the results of the column for me?
Amy
Upvotes: 1
Views: 1252
Reputation: 152266
You can use IF
statement in your SELECT
query.
In IF()
you specify some conditions and then name it as a column name:
SELECT col1, col2, IF(5 > 6, col3, '') AS col3 FROM table
Upvotes: 4