2013-04-10 170 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