Search code examples
sqlcasevarchar

Case ... When with strings in mysql


Hi I want to have some query like

Select 
 case column1
  when column2 like '%Test%' then column 3
  else 0
 end
FROM myTable

in column2 there are varchars stored. Can someone help me with this?


Solution

  • That doesn't make much sense. Why do you do a case on column1 but completely ignore that value afterwards? Did you just copy and (w)paste that into your query?

    Anyways, this is what I would expect to work in any of the ordinary RDBMS':

    case
      when colum2 like ...then
        3
      else
        0
      end as abc
    

    However, the only thing I know of mySQL is that it usually does everything different than your average Joe RDMS would do them.