2009-12-03 45 views
0

「專欄from子句是模糊的‘身份證’」:MySQL錯誤,但我前綴我的「ID」有鑑於查詢表

 
SELECT 
DISTINCT score.* 
FROM score 
LEFT OUTER JOIN tag ON (tag.id_score = score.id) 
INNER JOIN score AS score_1 USING (id) 
WHERE 
(score.song_name LIKE '%[Upload]%' 
    OR score.artist_name LIKE '%[Upload]%' 
    OR score.creator_name LIKE '%[Upload]%' 
    OR tag.name LIKE '%[Upload]%') 
AND (score_1.song_name LIKE '%[Check OK]%' 
    OR score_1.artist_name LIKE '%[Check OK]%' 
    OR score_1.creator_name LIKE '%[Check OK]%' 
    OR tag.name LIKE '%[Check OK]%') 

我得到Column 'id' in from clause is ambiguous在MySQL 5.1.37。通常人們通過在模棱兩可的列前添加一個明確的表來解決這個問題,但在這裏我已經這樣做了:(tag.id_score = score.id)。離開LEFT OUTER JOIN tag解決了問題,但不允許在標籤表內搜索。

這是MySQL中的錯誤還是我錯過了什麼?

回答

2

這不是要幫助,如果你改變

INNER JOIN score AS score_1 USING (id) 

INNER JOIN score AS score_1 (score_1.id_score = score.id) 
+0

是,INNER JOIN得分AS score_1 ON(score_1.id = score.id) 已刪除錯誤消息,但未給我任何結果。我想我需要使用子查詢/視圖,而不是將太多東西結合在一起。 – user113017 2009-12-03 15:44:36

0

在這種情況下我使用子查詢成功地這樣的:

 
SELECT * FROM (SELECT 
    DISTINCT score.* 
FROM score 
LEFT OUTER JOIN tag ON (tag.id_score = score.id) 
WHERE 
    (score.song_name LIKE '%[Upload]%' 
     OR score.artist_name LIKE '%[Upload]%' 
     OR score.creator_name LIKE '%[Upload]%' 
     OR tag.name LIKE '%[Upload]%') 


) AS score_0 INNER JOIN (SELECT 
    DISTINCT score.* 
FROM score 
LEFT OUTER JOIN tag ON (tag.id_score = score.id) 
WHERE 
    (score.song_name LIKE '%[Check OK]%' 
     OR score.artist_name LIKE '%[Check OK]%' 
     OR score.creator_name LIKE '%[Check OK]%' 
     OR tag.name LIKE '%[Check OK]%') 


) AS score_1 USING (id)