Liam Fell
Liam Fell

Reputation: 1320

mySQL: Issue with Left Join

I have the following query:

 SELECT c.`entity_id`,c. p.`name` as parent_id, c.`name`
  FROM category c
  LEFT JOIN category p WHERE c.`parent_id = p.id
  WHERE c.is_active = 1
  ORDER BY c.parent_id ASC, c.position ASC;

But I get an error on the first WHERE clause, can anyone spot the error here? Thanks

Upvotes: 0

Views: 16

Answers (1)

AnkiiG
AnkiiG

Reputation: 3488

You have added where clause twice. Try as below :

SELECT c.`entity_id`,c. p.`name` as parent_id, c.`name`
FROM category c
  LEFT JOIN category p on c.`parent_id = p.id
  Where c.is_active = 1
  ORDER BY c.parent_id ASC, c.position ASC;

Upvotes: 2

Related Questions