Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL change value

Tags:

sql

select

I'm trying to do a select query where I'm trying to change the value.

select * from config where category = 'basic'

For example I would like that the output shows 'general' instead of 'basic'. But I don't want to update all the 'basic' value's into 'general'

Is there a way to do this?

like image 251
Juraj Avatar asked Sep 08 '11 09:09

Juraj


2 Answers

Try this:

SELECT field1, field2, ...,
  CASE 
    WHEN category = 'basic' THEN 'general'
    ELSE category
  END
FROM config

or, in this particular case:

SELECT field1, field2, ...., 'general'
FROM config
WHERE category = 'basic'
like image 175
Marco Avatar answered Oct 18 '22 23:10

Marco


Make use of Case.. When statement resolve your issue

select 

  case when category = 'basic' then 'general' else category end

 from config
like image 43
Pranay Rana Avatar answered Oct 18 '22 23:10

Pranay Rana