MySQL: group by and IF statement

Posted by notset on Stack Overflow See other posts from Stack Overflow or by notset
Published on 2010-05-18T20:03:27Z Indexed on 2010/05/18 20:10 UTC
Read the original article Hit count: 124

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql