My task is to display first the number of products in category 5, then category 1 and then 2. This is the query I have:
SELECT
pc.category_name, p.category_id, COUNT(p.category_id) AS num_of_products
FROM
products p
INNER JOIN
product_categories pc
ON
p.category_id = pc.category_id
WHERE
p.category_id != 4 AND pc.category_id != 4
GROUP BY
pc.category_name, p.category_id;
And this is the output:
**CATEGORY_NAME CATEGORY_ID NUM_OF_PRODUCTS**
CPU 1 70
Video Card 2 50
Storage 5 108
How can I sort it in the required way? Maybe displaying the num_of_products column in a descendent order?
Thanks in advance.
ORDER BY NUM_OF_PRODUCTS DESC