0

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?

2
  • 2
    there's not much logic written in your example. Commented Nov 27, 2009 at 9:41
  • 2
    You should try and expalin the logic you wish to achieve. Commented Nov 27, 2009 at 9:46

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

this was simply an example but your answer fits my needs, thank you
0

Do you mean something like...

Select column3 from myTable where column2 like '%Test%'  
union all  
select 0 from myTable where column2 not like '%Test%'

Note that the "not like" operator can be slow

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.