MySQL中按索引排序,MySQL按索引ID从单独的表中排序

I have run into a problem that I'm sure is easy to achieve. I have a table for some merchandise. It holds all the information including the id for the manufacturer. The information about the manufacturer is in a separate table. When users are searching they have filter options. The one I'm having trouble with is filtering by manufacturer.

Products Table: cs_products

id | name | manufacturer_id

---------------------------

1 | mic | 3

2 | cable | 2

3 | speaker | 1

Manufacturer Table: cs_manufacturer

id | name

------------------

1 | JBL

2 | Rapco

3 | Shure

When the query is ran I need to ORDER BY cs_manufacturer.name:

mysql_query("SELECT * FROM cs_products ORDER BY cs_manufacturer.name")

What is the proper syntax for this?

解决方案SELECT * FROM cs_products JOIN cs_manufacturer

ON cs_product.manufacturer_id = cs_manufacturer.id

ORDER BY cs_manufacturer.name

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值