Hi all,
I have a product listing, the main table called products contains most product info each product contains a price, p_price, each product can also have a special offer applied to it, these offers are stored in a special offers table, special_offers. in this table i can track previous specials so that historical orders remain accurate. The current price of the product with an active special offer applied is stored in the special offers table. The problem i have is that i need to sort products by price, this works without special offers but not with offers as my current system relies on the p_price value to sort and therefore ignores the active special price. Adding a join to the special offers table will only return products with special offers and many dont so this isnt suitable either. I need to be able to sort by active special offer price (where this is one) and otherwise by price. I can think of numerous ways to do this by changing the db structure but ideally i dont want to touch this.
the code below is a sample query, i know this is incorrect but hopefully it might make it more obvious what i'm trying to do. thanks.
SELECT `p_id`,`so_showprice` AS `offer_price` FROM `ls_products` LEFT JOIN `ls_special_offer` ON (`so_pid` = `p_id`) ORDER BY `offer_price`,`p_price`