Cherry
Cherry

Reputation: 33554

Is it possible to match several value in case when statment for MySQL?

Consider example:

case when type = 'myValue' then 'default' else type end

how to listed several values here type = 'myValue'? Instead of duplicating:

case
     when type = 'myValue' then 'default'
     when type = 'other' then 'default'
     else type
end

Upvotes: 3

Views: 53

Answers (1)

Mureinik
Mureinik

Reputation: 311498

You can use any condition in a when clause. E.g., in your case, you could use the in operator:

case
     when type in ('myValue','other') then 'default'
     else type
end

Upvotes: 2

Related Questions