开发者

Why does SQL query return two rows when only one exists?

开发者 https://www.devze.com 2023-03-01 03:39 出处:网络
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

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;


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

Can you verify?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消