I have a select statement where I want to make the select conditional like this:
IFNULL(field_a, field_a, field_b)
so that it checks field a. If a is null then the select would be field b.
Is that possible ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use COALESCE:
COALESCE is an ANSI standard function that returns the first non-null value from the list of columns specified, processing the columns from left to right. So in the example, if
field_ais null,field_bvalue will be displayed. However, this function will return NULL if there is no non-null value from the columns specified.It’s supported on MySQL (I’ve used it on 4.1), SQL Server (since v2000), Oracle 9i+…