I want to select either price or sale_price with respect to the value in the field named nosale. where price, sale_price and nosale are fields of a product table.
The nosale field will be either true or false. According to that i want either the value of price or sale_price and not both.
How to form a single query to fetch like i mentioned?
SELECT IF(nosale = 1, price, sale_price) AS `something` FROM table ...
or
SELECT CASE WHEN nosale = 1 THEN price ELSE sale_price END AS `something` FROM table ...
http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With