MySQL: group by and IF statement
- by notset
By default, parent_id = 0. I want to select all records with parent_id = 0 and only the last ones with parent_id 0.
I tried this, but it didn't work:
SELECT * FROM `articles`
IF `parent_id` > 0 THEN
GROUP BY `parent_id`
HAVING COUNT(`parent_id`) >= 1
END;
ORDER BY `time` DESC
What could be the solution?