CREATE TABLE sections (<br/>
id_sections INT(11) NOT NULL AUTO_INCREMENT,<br/>
name VARCHAR(255) DEFAULT NULL,<br/>
parent INT(11) UNSIGNED NOT NULL,<br/>
PRIMARY KEY (id_sections)<br/>
)<br/>
SELECT s1.*, count(s2.id_sections)
FROM sections s1
LEFT JOIN sections s2 ON s2.parent = s1.id_sections
WHERE s1.parent = 0
GROUP BY s1.id_sections
SELECT *, (SELECT COUNT(*) FROM sections s2 WHERE s2.parent = s1.id_sections)
FROM sections s1
WHERE s1.parent = 0