MySQL:使用左/右字段获取连接(相似)数据

发布于 2024-09-14 00:54:25 字数 612 浏览 1 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事灯 2024-09-21 00:54:25

当您想知道这是否可能时,您可以查看 此信息嵌套集,这是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文