MySQL按索引ID从单独的表中排序 [英] MySQL Ordering by index id from separate table

查看:118
本文介绍了MySQL按索引ID从单独的表中排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个我确定很容易实现的问题.我有一张桌子可以买一些商品.它包含所有信息,包括制造商的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

运行查询时,我需要按cs_manufacturer.name排序:

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

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

正确的语法是什么?

推荐答案

SELECT * FROM cs_products JOIN cs_manufacturer
ON cs_product.manufacturer_id = cs_manufacturer.id
ORDER BY cs_manufacturer.name

这篇关于MySQL按索引ID从单独的表中排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆