合并自引用连接的 Mysql 查询
假设我有四个表:
------------- features --------------
id: int
name: varchar
-------------------------------------
-------- feature_categories ---------
feature_id: int
category_id: int
-------------------------------------
----------- categories --------------
id: int
name: varchar
-------------------------------------
------ category_subcategories -------
category_id: int
sub_category_id: int
-------------------------------------
类别有许多(子)类别,通过自引用连接子类别
一个功能有许多类别,其中一些将是子类别,通过连接 feature_categories
我需要的是发送一组功能 id 和一个(主) 类别 id 并返回所有子类别。事实证明,这比我希望的要困难,所以我非常感谢任何帮助。如果这个问题不清楚,请告诉我。
编辑 我不需要将特征表包含在任何查询中。在facet中,我只要求返回子类别(类别)名称字段。
Say I have four tables:
------------- features --------------
id: int
name: varchar
-------------------------------------
-------- feature_categories ---------
feature_id: int
category_id: int
-------------------------------------
----------- categories --------------
id: int
name: varchar
-------------------------------------
------ category_subcategories -------
category_id: int
sub_category_id: int
-------------------------------------
category has many (sub)categories, through self referential join subcategories
A feature has many categories, of those some will be subcategories, through join feature_categories
What I need is to send an array of feature ids and a (main) category id and have returned all subcategories. This is proving more difficult than I would have hoped so I'd appreciate greatly any help. Let me know if this question isn't clear.
EDIT
I don't need the feature table to be included in any query. In facet, I only require the subcategory (category) name field to be returned.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
必须解决这个问题,但下面的任何一个都应该可行。第二个可能更有效:
或者:
Had to work through this a bit, but either below should work. 2nd one is probably more efficient:
or:
以下内容可以完成这项工作吗?
does the following do the job?
如果我正确理解你在问什么......
If I understand correctly what you are asking...
这可能会给出预期的结果
This may give expected result