2013-04-10 155 views
1

任何人都可以在這裏看到錯誤。 PhpMyAdmin告訴我在where子句附近有一個錯誤。我無法弄清楚的sql錯誤

SELECT product.*, category.*,store.* 
WHERE 
    store.store_id = product.store_id AND 
    category.category_id = product.category_id 
INNER JOIN store ON store.store_name = 'mens' 
INNER JOIN category ON category.category_name = 'rings' 

回答

5

INNER JOIN所屬的FROM子句中,而不是在WHERE子句。 FROM條款完全缺失。

SELECT product.*, category.*, store.* 
    FROM product, category, store 
WHERE store.store_id = product.store_id AND 
     category.category_id = product.category_id AND 
     store.store_name = 'mens' AND 
     category.category_name = 'rings' 
5

在sql中沒有FROM子句。

select product.*, category.*, store.* from product 
inner join .... 
2

你似乎混淆了你的whereon條款的目的。

SELECT product.*,category.*,store.* 
From Product 
INNER JOIN store on store.store_id = product.store_id 
inner join category on category.category_id = product.category_id 
where store.store_name= 'mens' and category.category_name = 'rings' 
2

Select查詢中的每個主要子句必須按正確的順序排列。

的順序是:

Select ... [Output fields and expressuions] -- Required 
From ... [list of tables, with joins and join conditions] -- Required 
Where [Predicates and filter conditions] -- Optional 
Group By [list of fields/expressns to group results by] -- reqr'd for aggregate queries 
Order By [List of fields and expressions to sort results by -- optional