Mike Rifgin
Mike Rifgin

Reputation: 10761

Sql error that I can't figure out

Can anyone see the error here. PhpMyAdmin tells me I have an error near the where clause.

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'

Upvotes: 1

Views: 58

Answers (4)

Charles Bretana
Charles Bretana

Reputation: 146541

Each major clause in a Select query must be in the proper order.

The order is:

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

Upvotes: 2

NPE
NPE

Reputation: 500673

INNER JOIN belongs in the FROM clause, not in the WHERE clause. The FROM clause is missing entirely.

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'

Upvotes: 5

Brad
Brad

Reputation: 12253

You seem to be mixing up the purpose of your where and on clauses.

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'

Upvotes: 2

Kal
Kal

Reputation: 24910

There is no FROM clause in your sql.

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

Upvotes: 5

Related Questions