i have written this mysql query:
SELECT * , 1 AS haschild
FROM table2
WHERE parentid = '0'
AND pid IN ( SELECT parentid FROM table2 )
UNION
SELECT * , 0
FROM table2
WHERE parentid = '0'
AND pid NOT IN ( SELECT parentid FROM table2 )
ORDER BY pid
but i think it is so silly query !! hope you can get my meaning of this query and guide me to write a better one.
thanks.