Reputation: 1703
I need to sort products by 3 different fields
So I need to order by every day first and then get the featured before the non featured once.
SELECT * FROM products ORDER BY ...., featured DESC;
As you can see I miss the part with the date and I cannot find a solution for that.
Thanks in advance for any hint.
Upvotes: 0
Views: 457
Reputation: 204746
In MySQL you can do
SELECT * FROM products
ORDER BY date(created_at),
featured <> 1;
and generally this works for all DB engines
SELECT * FROM products
ORDER BY date(created_at) ASC,
case when featured = 1 then 1 else 0 end DESC;
Upvotes: 1