.... ..... if ($prod_price->RecordCount()>0) { $p_price = $prod_price->fields['options_values_price']; } else { $p_price = $orders_products_query->fields['products_price']; } $p_price = ($p_price>0)?$p_price:$orders_products_query->fields['final_price']; ...... ..........
As you can guess from the above, I run two different queries and check 3 fields to determine the $ p_price variable in PHP. I want to condense this in one query, conditions: If field1 is Null, use field2, if field2 is 0, use field 3.
The first part can be solved with IFNULL (field1, field2) .... but what should I do with the second part? Should I use a case? I need the most efficient solution in terms of execution speed, because it is part of an extremely large request.
EDIT:
Since it seems that some of you have not understood, take this as an alternative.
IF(IFNULL(field1,field2)>0,IFNULL(field1,field2),field3) The above MySQL query condition works with the above logic, but as you can see, it double-evaluates field1 and field2 to check for NULL, which, in my opinion opinion is not very efficient, so I'm looking for the best query / condition to rewrite the same.
source share