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