Rewrite MySQL SELECT statement so error isn't generated
Posted on 2011-05-05
I need to query a table such that if the content of a column equals my value, then it returns the value of another column; but if not, then return nothing and generate no warning. (Returning "false" would also be fine, or any other legal value to tell me my value doesn't exist.)
For example, let's say I submit this query:
"SELECT firstname FROM table WHERE lastname='Jones'"
I want to write this so it means: If there is a row with a lastname value of "Jones", then return the firstname value. If not, return nothing.
But if I use this statement as is and there is no row where the lastname is "Jones", MySQL generates an "Unable to jump to row 0" warning.
How can this statement be rewritten so that if my value is not found, a warning will not be generated?