MySQL:使用左/右字段获取连接(相似)数据
在 MySQL 中,我有两个表:
- PRODUCTS (id, Name)
- SEEALSO (id, prodLeft, prodRight)
SEEALSO 定义哪些产品相关,并表示为绑定字段“prodLeft”-“prodRight”。 例如:
产品:
- 1 桌子
- 2 桌子
- 3 椅子
- 4 门
- 5 树
- 6 花
SEEALSO
- 1 1 2
- 2 2 3
- 3 3 4
- 4 5 6
由此可见桌-桌-椅-门的绑定 和树花。 我现在想要编写 SQL 语句,在其中可以指定产品名称(例如 Chair),并且我将获得与其连接的绑定字段的结果(例如 Chair: Desk-Table-Chair -门)。 从现在起,我想知道这对于我在 SEEALSO 中的数据呈现概念是否可行,如果可以,您是否可以帮助我解决我的问题。
In MySQL Im having two tables:
- PRODUCTS (id, Name)
- SEEALSO (id, prodLeft, prodRight)
SEEALSO defines which PRODUCTS are related together and are represented as binded fileds "prodLeft"-"prodRight".
For Example:
PRODUCTS:
- 1 Desk
- 2 Table
- 3 Chair
- 4 Doors
- 5 Tree
- 6 Flower
SEEALSO
- 1 1 2
- 2 2 3
- 3 3 4
- 4 5 6
From that we can see binding of Desk-Table-Chair-Doors and Tree-Flower.
I would now want to write SQL statement where I could specifie PRODUCT name (e.g. Chair) and i would get result of binded fields that are connected with it (e.g. Chair: Desk-Table-Chair-Doors).
From this point on i would like to know if this is even possible for my data presentation concept in SEEALSO and if it is if you could help me solve my problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您想知道这是否可能时,您可以查看 此信息嵌套集,这是 MySQL 执行此操作的方式(我收集)。
我无法给你一个有效的示例,因为我不是 MySQL 专家:考虑到你问题的一般性质,也许这对你有足够的帮助。
As you're wondering whether it's even possible, you could look into this information on Nested Sets, which is the MySQL way of doing this (I gather).
I could not give you a worked sample, as I'm no MySQL expert: perhaps this will help you enough given the general nature of your question.