My table:
$query = "CREATE TABLE categories (
id int(11) NOT NULL auto_increment,
name varchar(100) NOT NULL,
parent int(11) NOT NULL,
visible tinyint(11) NOT NULL DEFAULT 1,
PRIMARY KEY (id)
)" ;
The query:
SELECT t1.id ,t1.name FROM
flipkart_categories AS t1 LEFT JOIN categories as t2
ON t1.id = t2.parent
WHERE t2.id IS NULL AND t1.parent = 141
The idea here is to retrieve all the leaf nodes of a particular parent. But the thing is some categories are like
category > subcategory > item , whereas some are like
category > items
The above query only retrieves if there is no subcategory. Can there be a query that can handle both the above cases ?
Thanks