2011-04-28 53 views
0

我寫了一個內部連接來從一個數據庫中的三個表中提取信息。當我運行查詢時,我得到兩行返回,第二行是第一行的副本。我希望只有一行被返回?爲什麼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; 
+1

此查詢是否返回2行'select * from application_price WHERE application_price.application_id = 353783927;'?如果是這樣,那就是答案。 – Augusto 2011-04-28 16:07:28

回答

3

我認爲你有兩個記錄application_price表,其中euroapps.id = 353783927.

你能證實嗎?

+2

agh,多麼笨,我非常專注於在euroapps中尋找重複項目,我忘記了其他表格中的重複項目,談論沒有看到樹木的木材,非常感謝! – kitenski 2011-04-28 16:13:27

1

看起來您的application_price表有兩個匹配的行。

嘗試從application_price中選擇外鍵出現兩次,並且您會找到您的罪魁禍首。

1

我的猜測是application_price表包含兩行application_id「353783927」。 「select * from application_price where application_price.application_id = 353783927」返回什麼?我的猜測是你有一個模式,application_price指定euroapp的差價。

您似乎沒有使用application_price的值,所以我不確定爲什麼要加入它。