我有两个MySQL表,一个带有类别,一个带有产品。对于第一个,我还有一列描述类别顺序。我想做的是获取所有产品,然后按类别(需要根据“订单”字段升序排序)和价格(也升序)对其进行排序。
这些表是:
categories
-id, (int)
- name, (text)
- order (int)
products
- id, (int)
- model, (text)
- price, (float)
- category_id (int)
最佳答案
Select id, model, price
from products p , categories c
where c.id = p.category_Id
order by c.order, p.price