[英]Reading a database diagram
I've been trying to figure out how to get the products that match a certain category id but I have been unable to figure out how to move from category to products. 我一直在试图找出如何获得与某个类别ID相匹配的产品,但一直无法弄清楚如何从类别转到产品。
How would a query that basically selects all products that match a certain category id look? 基本上选择与某个类别ID匹配的所有产品的查询将如何显示?
This should work: 这应该工作:
SELECT products.*
FROM products,
product_category
WHERE product_category.categoryid = CATEGORY_ID
AND products.catalogid = product_category.catalogid
Or if you prefer a join: 或者,如果您喜欢加入:
SELECT products.*
FROM products
INNER JOIN product_category ON products.catalogid = product_category.catalogid
WHERE product_category.categoryid = CATEGORY_ID
Simply replace CATEGORY_ID
by the ID of the category you wish to select. 只需将
CATEGORY_ID
替换为您想要选择的类别的ID。
product_category
is a link table, joining the tables products
and product_category
together: it contains the catalogid
, referencing the ID of the category, and catalogid
, referencing the ID of the product. product_category
是一个链接表,将表products
和product_category
结合在一起:它包含catalogid
(引用类别的ID)和catalogid
(引用产品的ID)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.