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

编程入门 行业动态 更新时间:2024-10-27 10:32:33
本文介绍了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从单独的表中排序

本文发布于:2023-11-22 05:16:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616114.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:索引   MySQL   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!