2011-07-22 64 views
2

我收到此錯誤:#1054 - 未知列「t.mobile」在「關於條款」獲得MySQL錯誤1054

SELECT t.*,v.name,v.contact_person_email,l.firstname as memname 
FROM transactions t , vendor v 
LEFT JOIN loyalty_members l ON (t.mobile=l.mobile) 
WHERE t.vendor_id ='N1WU95' 
AND v.alert_mail = '2' 
AND t.add_date <= '2011-07-22 09:00:00' 
AND t.add_date >= '2011-07-21 09:00:00' 
AND t.vendor_id = v.id 
AND t.type = '1' 
AND t.deleted != '1' 
AND t.reference_id = '0' 
GROUP BY t.mobile 
HAVING COUNT(t.mobile) > 1; 

任何人都可以請幫我解決了這一點?

謝謝。

+2

請給出表格架構! – rabudde

+2

列表'transactions'中是否存在'mobile'列? – Shef

+0

所以我們看到另一個例子,爲什麼SELECT *不好 – wonk0

回答

6

嘗試:

SELECT t.*, v.name, v.contact_person_email, l.firstname memname 
    FROM vendor v, transactions t 
LEFT JOIN loyalty_members l ON t.mobile = l.mobile 
    WHERE t.vendor_id ='N1WU95' 
     AND v.alert_mail = '2' 
     AND t.add_date <= '2011-07-22 09:00:00' 
     AND t.add_date >= '2011-07-21 09:00:00' 
     AND t.vendor_id = v.id 
     AND t.type = '1' 
     AND t.deleted != '1' 
     AND t.reference_id = '0' 
GROUP BY t.mobile 
    HAVING COUNT(t.mobile) > 1; 

你在做一個LEFT JOIN與錯誤的表順序。引擎試圖加入vendor表與loyalty_members表。

+2

哇,我不知道表序列的順序可能會有影響。很好的發現。 –

1

簡而言之,表transactions中的「移動」列不存在。

+0

是的。沒有太多的錯誤信息比這更清楚。 – ceejayoz

+2

@ScottMcGready:不,這不是。我懷疑它是唯一的,但第二眼看上去,OP正在'loyalty_members'的'vendors'表上做'LEFT JOIN',這顯然不是正確的順序。 @ceejayoz:似乎不夠清楚。 :) – Shef