Captain Stack
Captain Stack

Reputation: 3844

How can I make SELECT return a pre-defined string instead of a boolean (integer)?

My Food table has columns Name, Food Group, and Healthy. Healthy is a boolean represented by INTEGER 1 for healthy foods and 0 for unhealthy foods. I want a query that returns all three columns but for Healthy I want it to return "Eat me" for healthy foods and "Avoid me" for unhealthy foods.

How do I write this query using only a SELECT statement?

Upvotes: 0

Views: 71

Answers (1)

user1129665
user1129665

Reputation:

You can use CASE expression here like:

select Name, case Healthy when 1 then "Eat me" else "Avoid me" end from Food;

Upvotes: 1

Related Questions