为什么 SQL 查询在只有一行存在时返回两行?

发布于 2024-11-03 18:11:51 字数 1032 浏览 1 评论 0原文

我编写了一个内部联接来从一个数据库中的三个表中提取信息。当我运行查询时,我返回两行,第二行是第一行的重复项。我希望只返回一行?

查询:

mysql> SELECT euroapps.id, euroapps.name, euroapps.imageurl, euroapps.website,
   euroapps.developer, euroapps.description, euroapps.created, euroapps.iphone,
   euroapps.ipodtouch, euroapps.ipad,  app_detail.screen1 , app_detail.screen2,
   app_detail.screen3, app_detail.screen4, application_price.retail_price
FROM euroapps INNER JOIN app_detail ON euroapps.id = app_detail.id
 INNER JOIN application_price ON euroapps.id= application_price.application_id
 WHERE euroapps.id = 353783927;

返回两行,而此查询仅返回一行(并且符合预期)

mysql> SELECT euroapps.id, euroapps.name, euroapps.imageurl, euroapps.website,
euroapps.developer, euroapps.description, euroapps.created, euroapps.iphone,
euroapps.ipodtouch, euroapps.ipad,  app_detail.screen1 , app_detail.screen2,
app_detail.screen3, app_detail.screen4
FROM euroapps INNER JOIN app_detail ON euroapps.id = app_detail.id
WHERE euroapps.id = 353783927;

I have written an inner join to pull information from three tables within one database. When I run the query I get two rows returned, the second being a duplicate of the first row. I would expect only one row to be returned?

The query:

mysql> SELECT euroapps.id, euroapps.name, euroapps.imageurl, euroapps.website,
   euroapps.developer, euroapps.description, euroapps.created, euroapps.iphone,
   euroapps.ipodtouch, euroapps.ipad,  app_detail.screen1 , app_detail.screen2,
   app_detail.screen3, app_detail.screen4, application_price.retail_price
FROM euroapps INNER JOIN app_detail ON euroapps.id = app_detail.id
 INNER JOIN application_price ON euroapps.id= application_price.application_id
 WHERE euroapps.id = 353783927;

returns two rows, whereas this one only returns one row (And is as expected)

mysql> SELECT euroapps.id, euroapps.name, euroapps.imageurl, euroapps.website,
euroapps.developer, euroapps.description, euroapps.created, euroapps.iphone,
euroapps.ipodtouch, euroapps.ipad,  app_detail.screen1 , app_detail.screen2,
app_detail.screen3, app_detail.screen4
FROM euroapps INNER JOIN app_detail ON euroapps.id = app_detail.id
WHERE euroapps.id = 353783927;

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

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

发布评论

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

评论(3

久伴你 2024-11-10 18:11:51

我认为您在 application_price 表中有两条记录,其中 euroapps.id = 353783927。

您可以验证吗?

I would think that you have two records in application_price table where the euroapps.id = 353783927.

Can you verify?

删除会话 2024-11-10 18:11:51

您的 application_price 表似乎有两行匹配。

尝试从 application_price 中进行选择,其中外键出现两次,您就会找到罪魁祸首。

It appears that your application_price table has two rows that are matching.

Try a select from application_price where the foreign key appears twice, and you'll find your culprit.

混吃等死 2024-11-10 18:11:51

我的猜测是 application_price 表包含 application_id“353783927”的两行。 “select * from application_price where application_price.application_id = 353783927”返回什么?我的猜测是您有一个模式,其中 application_price 指定 euroapp 的差异价格。

您似乎没有使用 application_price 思想中的值,所以我不确定您为什么要加入它。

My guess would be that the application_price table contains two rows for application_id "353783927". What does "select * from application_price where application_price.application_id = 353783927" return. My guess would be you have a schema where application_price specifies difference prices for a euroapp.

You don't seem to be using and values from application_price thought and so I'm not sure why you're joining it.

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