I have a mysql table with products.
The products have a category ID and a name.
What I’d like to do is order by category id first descending order and then order by product name ascending order.
SELECT * FROM `products` ORDER BY `products`.`product_category_id`,`naam` DESC
What i’d like is
SELECT * FROM `products` ORDER BY `products`.`product_category_id`,`naam` DESC,ASC
but that unfortunately doesn’t work.
Is this even possible in mysql to define the sorting order of the second sorting column?
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
You can do that in this way:
ORDER BY `products`.`product_category_id` DESC ,`naam` ASC
Have a look at
ORDER BY Optimization
I don’t understand what the meaning of ordering with the same column
DESC in the same
ORDER BY, but this how you can do it:
naam DESC, naam ASC like so:
ORDER BY `product_category_id` DESC,`naam` DESC, `naam` ASC