Get name column instead of ids from two foreign keys
You need to use 2 copies of names table:

SELECT groups_1.name AS gname, groups_2.name AS pname
FROM inheritance
JOIN groups AS groups_1 ON inheritance.gid = groups_1.id
JOIN groups AS groups_2 ON inheritance.pid = groups_2.id