[英]MySQL Ordering by index id from separate table
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. 它包含所有信息,包括制造商的ID。 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: 当查询运行时,我需要按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
You are missing your join. 您错过了加入。
SELECT * FROM cs_products
JOIN cs_manufacturer on cs_products.manufacturer_id = cs_manufacturer.id
ORDER BY cs_manufacturer.name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.