mysql连接基本问题

发布于 2024-11-15 03:01:30 字数 343 浏览 1 评论 0原文

我有一个非常基本的问题,我想需要加入才能解决。不过我对 mysql 很陌生!这是我需要完成的:

我有 3 个表:

Productsattributesproducts_to_attributes

我需要做的是选择属性它们与我想要查询的产品相关联,基于 products_to_attributes 表。

假设我的产品 id=1,我需要根据 products_to_attributes 表获取属性表中的所有行,该表仅保存 pid 以提供帮助。

I have a pretty basic question that I imagine would require a join to pull off. However I am very new to mysql! Here is what I need to pull off:

I have 3 tables:

Products, attributes, and products_to_attributes

What I need to do is select the attributes which are associated to the product I want to query, based off the products_to_attributes table.

So lets say my product id=1, I need to grab all the rows in the attributes tables based off the products_to_attributes table which simply holds the pid to aid.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

难理解 2024-11-22 03:01:30
SELECT a.*
FROM attributes a
INNER JOIN products_to_attributes pa ON a.aid = pa.aid
WHERE pa.pid = 1
SELECT a.*
FROM attributes a
INNER JOIN products_to_attributes pa ON a.aid = pa.aid
WHERE pa.pid = 1
走过海棠暮 2024-11-22 03:01:30
SELECT a.*
FROM attributes a, products_to_attributes  b
WHERE a.aid = b.aid
AND b.pid = 1

它与 tofutim 的答案基本上相同,但不使用 INNER JOIN 语法。

SELECT a.*
FROM attributes a, products_to_attributes  b
WHERE a.aid = b.aid
AND b.pid = 1

it's basically the same answer as tofutim, but without using the INNER JOIN syntax.

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