ilhan
ilhan

Reputation: 8995

Converting integer to text during the select query in MySQL

I'm trying to select an integer field as text but I have no idea how to do it.

The 1 represents low, the 2 represents medium, and 3 represents hi.

Upvotes: 0

Views: 73

Answers (3)

Habib
Habib

Reputation: 223402

Select 
CASE WHEN field = 1 then 'low' 
WHEN field = 2 then 'medium'
WHEN field = 3 then 'hi'
END as Col
from yourtable;

Upvotes: 2

sel
sel

Reputation: 4957

SELECT CASE intfield
        WHEN 1 THEN 'low'
        WHEN 2 THEN 'medium'
        WHEN 3 THEN 'hi'       
    END AS inttext
FROM table

Upvotes: 2

Omesh
Omesh

Reputation: 29121

you can do this with CASE WHEN

SELECT (CASE WHEN column = 1 THEN "low"
             WHEN column = 2 THEN "medium"
             WHEN column = 3 THEN "high"
        END) AS value
FROM table_name;

Upvotes: 3

Related Questions