farshad1123
farshad1123

Reputation: 325

How can i change column value in sql query result, not in database?

I have a table named user. In this table, there is a column named 'Sex', which has value 'm' or 'f'. I want to present these values as 'male' or 'female' without changing the exact value in the database. What is the best way?

Upvotes: 0

Views: 1213

Answers (2)

Ilyes
Ilyes

Reputation: 14928

Using a CASE expression since you have only 'm' and 'f'

SELECT
    Sex,
    CASE Sex WHEN 'm' THEN 'male'
             else 'female' END AS SexLabel
FROM yourTable;

Upvotes: 0

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521289

Use a CASE expression:

SELECT
    Sex,
    CASE Sex WHEN 'm' THEN 'male'
             WHEN 'f' THEN 'female' END AS SexLabel
FROM yourTable;

Upvotes: 5

Related Questions