简体   繁体   English

从 2 个表 SQL Server 创建多级菜单

[英]Create multi level menu from 2 tables SQL Server

I create 2 tables like below: Category(id, category_name)我创建了 2 个表,如下所示: Category(id, category_name)
Product(id, product_name, category_id)产品(id,product_name,category_id)
How do I create a menu like that with SQL Server?如何使用 SQL Server 创建这样的菜单?
A category一个类别
++ Product 1 ++ 产品 1
++ Product 2 ... ++ 产品 2 ...
B category B类
++ Product 3 ++ 产品 3
++ Product 4 ++ 产品 4
Thanks for watching!感谢收看!

You can JOIN the 2 tables and list them according to "category_name".您可以 JOIN 2 个表并根据“category_name”列出它们。 I would do the following:我会做以下事情:

SELECT * FROM Category INNER JOIN Product ON Category.id = Product.category_id ORDER BY Category.category_name, Product.product_name ASC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM