为什么 SQL 查询在只有一行存在时返回两行?
我编写了一个内部联接来从一个数据库中的三个表中提取信息。当我运行查询时,我返回两行,第二行是第一行的重复项。我希望只返回一行?
查询:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您在
application_price
表中有两条记录,其中euroapps.id
= 353783927。您可以验证吗?
I would think that you have two records in
application_price
table where theeuroapps.id
= 353783927.Can you verify?
您的 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.
我的猜测是 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.