I need to write a query to select products from a database for a search page, at the moment the query is really simple
SELECT * FROM products WHERE stock > 0 ORDER BY id DESC
This query brings back products fine starting from the newest, we will be going into sale soon so I need to change the query to order by the newest product on sale descending, then go onto display the remaining products that aren’t on descending. If a product is on sale rrp is not equal to 0. Is there a way where I can do this without having to run two separate queries?
Is was thinking something like
SELECT * FROM products WHERE stock > 0 ORDER BY (rrp != 0) DESC, id DESC
but that doesn’t work.
Thanks in advance
try this: