Change 1 and 0 to TRUE and False

Hey,
I tried to use a case to change the 1 and 0 but it wasn’t working,there were no suggestions in the Hints how to do it.
HERE is the code with results in 1 and 0
SELECT DISTINCT quiz.user_id,
home_try_on.user_id IS NOT NULL AS ‘is_home_try_on’,
home_try_on.number_of_pairs,
purchase.user_id IS NOT NULL AS ‘is_purchase’
FROM quiz
LEFT JOIN home_try_on
ON quiz.user_id = home_try_on.user_id
LEFT JOIN purchase
ON purchase.user_id = quiz.user_id
LIMIT 10;

Here is the code with the case statement (How I tried)
SELECT DISTINCT quiz.user_id,
home_try_on.user_id IS NOT NULL AS ‘is_home_try_on’,
home_try_on.number_of_pairs,
purchase.user_id IS NOT NULL AS ‘is_purchase’
CASE WHEN is_home_try_on.user_id = 1 THEN ‘TRUE’
WHEN is_purchase.user_id = 1 THEN ‘TRUE’
ELSE ‘False’
END
FROM quiz
LEFT JOIN home_try_on
ON quiz.user_id = home_try_on.user_id
LEFT JOIN purchase
ON purchase.user_id = quiz.user_id
LIMIT 10;
Thank you in Advance :slightly_smiling_face:

Hello, @resiewsoka.

The syntax can be a little tricky. Here’s an example:

SELECT DISTINCT 
   CASE column_name IS NOT NULL WHEN 1 THEN 'True' ELSE 'False' END AS 'alias'

Thank you :slight_smile:

1 Like