How to combine UNION and INNER JOIN?
Just do a LEFT JOIN instead:

SELECT P.id, P.parent, GP.parent gp_id FROM product_groups P             
LEFT JOIN product_groups GP ON P.parent = GP.id


That will return all rows from P and any non-matching rows in GP will have NULL values.