views:

202

answers:

1

I am using CakePHP for a price-comparison website.

I have a table products with fields: id, pride_regular, price_action.

I would like to combine the fields price_regular and price_action into a dynamic field: price. The lowest value of these two fields should be the value of the new price field. Also I want to order on it Ascending.

Should I use a custom MySQL-query?

A: 

This SQL query will get lowest values (except NULL values) over two columns:

SELECT LEAST(price_month_regular, ifnull(price_month_action, 9999)) AS least FROM cp_contracts ORDER BY least

Atea