MySQL Forums
Forum List  »  General

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

Written By
CASE in select query
April 04, 2012 02:31PM
April 04, 2012 02:52PM
April 04, 2012 03:17PM
April 04, 2012 03:20PM
April 05, 2012 07:45PM
April 05, 2012 08:02PM
April 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.