2011-10-05 51 views
0

我有添加到長期複雜的查詢

Select 
cards.card_id, 
    cards.item_name, 
    cards.meta_description, 
    cards.description, 
    '' as Weight, 
    '' as UPC, 
    '' as Part, 
    cards.seo_keywords, 
    concat('',cards.card_id,'_shadow.png') AS ImageURL, 
    lookup_details.value, 
    concat('ARTIST - ', card_import.artist) AS Brand, 
replace(lower(concat('http://www.test.com/', pcat.seoname,'/',cat.seoname, '/', cards.seoname, '.htm')),' ','+') AS link, 
      concat(pcat.name,' > ',cat.name) as Merchant, 
round(min(card_lookup_values.card_price), 2) AS 'price', 
min(cast(lookup_details.value as signed)) as 'quantity' 

FROM 
    cards 
    left join card_import on card_import.card_id = cards.card_id 
    join card_lookup_values on card_lookup_values.card_id = cards.card_id 
      INNER JOIN card_categories cc ON cards.card_id = cc.card_id AND cards.card_live = 'y' AND cards.active = 'y' AND cc.active = 'Y' 
      INNER JOIN categories cat ON cat.category_id = cc.category_id AND cat.active = 'Y' 
      INNER JOIN categories pcat ON cat.parent_category_id = pcat.category_id 
INNER JOIN card_lookup_values as card_values ON cards.card_id = card_values.card_id 
INNER JOIN lookup_details ON card_lookup_values.lookup_detail_id = lookup_details.lookup_detail_id 

WHERE card_lookup_values.lookup_id = 7,lookup_details.lookup_id= 40 
GROUP BY 
    cards.card_id 
ORDER BY 
    cards.card_id 

查詢我想我擁有了一切設置正確,但我不斷收到在Navicat一個錯誤,說我有近一個錯誤**

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'lookup_details.lookup_id= 40 
GROUP BY 
    cards.card_id 
ORDER BY 
    cards.card_' at line 28 

**

難道我只是想念這個嗎?

+0

在「where」子句中,這兩者之間不需要布爾運算符嗎? WHERE card_lookup_values.lookup_id = 7,lookup_details.lookup_id = 40 – bleeeah

+0

我可能得到一個個性化的嬰兒圍兜 - 我是一個凌亂的食客! - *「請站起來,程序員在吃。」* – RedFilter

+0

哇。 7分鐘內答案(計數評論),並基本上都得到了它。這就像一個射擊隊。瑣碎的錯誤不應該在這裏附近。 –

回答

3

你想要AND或OR(以適當爲準)你的WHERE條件在一起。

... 
WHERE card_lookup_values.lookup_id = 7 AND lookup_details.lookup_id= 40 
... 

... 
WHERE card_lookup_values.lookup_id = 7 OR lookup_details.lookup_id= 40 
... 
0

正確的SQL語法使用的WHERE子句AND關鍵字。

WHERE blahblah = blah AND trala = la 
0
WHERE card_lookup_values.lookup_id = 7,lookup_details.lookup_id= 40 

應該

WHERE card_lookup_values.lookup_id = 7 AND lookup_details.lookup_id= 40 

不要在最後忘了分號呢!

0

改變這一行

WHERE card_lookup_values.lookup_id = 7,lookup_details.lookup_id= 40 

這個

WHERE card_lookup_values.lookup_id = 7 and lookup_details.lookup_id= 40 
1

你甲肝一個額外的逗號

WHERE card_lookup_values.lookup_id = 7,lookup_details.lookup_id= 40 

應該

WHERE card_lookup_values.lookup_id = 7 AND lookup_details.lookup_id= 40