user2585047
user2585047

Reputation:

MySql display int as value

i'd like to store into a mailbox table the folder, the message should be inside as an int. Like 0 is inbox, 1 is outbox, ...

Is there a way to make the result of the query give me back a result like 'INBOX' for the stored value of 0?

Greetings

Upvotes: 0

Views: 76

Answers (3)

Nir Alfasi
Nir Alfasi

Reputation: 53525

You can use a nested IF statement:

select if(folder=0, 'Outbox', if(folder=1, 'Inbox', 'Sent')) as folder, msg_id,... from messages; 

Upvotes: 0

RiaD
RiaD

Reputation: 47619

You may store them as ENUM('INBOX', 'OUTBOX'). They will be stored as integers.

It'll be possible to write them as strings and as integer representation. They will be read as text by default.

Upvotes: 1

Akhil
Akhil

Reputation: 2602

select case message when 1 then 'INBOX' when 2 then 'OUTBOX' END from your table

Is this what you are looking for?
Refer this for more information

Upvotes: 0

Related Questions