2014-02-11 48 views
-1
Not unique table/alias: 'm3' 


SELECT count(distinct e.guid) as total 
From elgg_entities e JOIN elgg_metadata m ON e.guid = m.entity_guid 
        JOIN elgg_metadata m2 ON e.guid = m2.entity_guid 
        JOIN elgg_metadata m3 ON (e.guid = m3.entity_guid) 
        JOIN elgg_metadata m3 ON (e.guid = m3.entity_guid) 
        JOIN elgg_metastrings v ON v.id = m.value_id 
        JOIN elgg_metastrings v2 ON v2.id = m2.value_id 
WHERE e.type='object' AND 
     e.subtype=32 AND 
     m3.name_id='120908' AND 
     m3.value_id='1399' AND 
     m3.name_id='145634' AND 
     m3.value_id='145635' AND 
     e.site_guid = 1 AND 
     ((1 = 1) AND e.enabled='yes' OR (e.owner_guid = 2 AND e.enabled='no')) AND 
     ((1 = 1) AND m.enabled='yes' OR (m.owner_guid = 2 AND m.enabled='no')) AND 
     ((1 = 1) and m2.enabled='yes' OR (m2.owner_guid = 2 AND m2.enabled='no')) 

查詢中有什麼錯誤?如何解決它。錯誤:非唯一表/別名:MySQL中的'm3'

+2

'elgg_metadata m3'然後'elgg_metadata m3' - 在這裏你去 –

回答

4

是......你是一個別名m3加入elgg_metadata兩次......將其更改爲m4或類似這樣的

SELECT 
    count(distinct e.guid) as total 
from elgg_entities e 
JOIN elgg_metadata m 
    ON e.guid = m.entity_guid 
JOIN elgg_metadata m2 
    on e.guid = m2.entity_guid 
JOIN elgg_metadata m3 
    ON (e.guid = m3.entity_guid) 
JOIN elgg_metadata spongebob ON (e.guid = spongebob.entity_guid) 
JOIN elgg_metastrings v on v.id = m.value_id JOIN elgg_metastrings v2 on v2.id = m2.value_id 
WHERE e.type='object' and e.subtype=32 and m3.name_id='120908' and m3.value_id='1399' and m3.name_id='145634' and m3.value_id='145635' and e.site_guid = 1 and ((1 = 1) and e.enabled='yes' OR (e.owner_guid = 2 AND e.enabled='no')) and ((1 = 1) and m.enabled='yes' OR (m.owner_guid = 2 AND m.enabled='no')) and ((1 = 1) and m2.enabled='yes' OR (m2.owner_guid = 2 AND m2.enabled='no')) 
0

另一個別名您正在使用別名立方米兩次在這裏

JOIN elgg_metadata m3 ON (e.guid = m3.entity_guid) 
JOIN elgg_metadata m3 ON (e.guid = m3.entity_guid) 
相關問題