Skip navigation links

MySQL Forums :: General :: CASE in select query


Advanced Search

CASE in select query
Posted by: jim giner ()
Date: April 04, 2012 02:31PM

I vaguely remember using a case clause in a select statement in a former occupation, but now that I am using mysql (with php) I am encountering my first need for it and don't know if I can do what I want.

I need to add a sequencing field to my query results based upon whether a column in my query is equal to or not equal to another column in the same row of my results. All the Case examples I run across in my searches show something like:
case (fldname) when '1' then '2' when '2' then '3' end as (newfldname)

What I would like to do is:

case (fldname) when (= otherfld) then '1' else '0' end as srtfld

Can you do this kind of thing?

Options: ReplyQuote


Subject Written By Posted
CASE in select query jim giner 04/04/2012 02:31PM
Re: CASE in select query jim giner 04/04/2012 02:52PM
Re: CASE in select query laptop alias 04/04/2012 03:17PM
Re: CASE in select query jim giner 04/04/2012 03:20PM
Re: CASE in select query Rick James 04/05/2012 07:45PM
Re: CASE in select query jim giner 04/05/2012 08:02PM
Re: CASE in select query Peter Brawley 04/05/2012 08:27PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.