First I am going to rewrite your query
select username from mdl_user where id = (select userid from mdl_role_assignments where roleid = (select id from mdl_role where shortname = 'parent'))
to use joins instead of nested subqueries
SELECT username
FROM mdl_user user
JOIN mdl_role_assignments ra ON ra.userid = user.id
JOIN mdl_role role ON role.id = ra.roleid
WHERE role.shortname = 'parent'
Now to add the link to the child
SELECT user.username AS parent, child.username AS child
FROM mdl_user user
JOIN mdl_role_assignments ra ON ra.userid = user.id
JOIN mdl_role role ON role.id = ra.roleid
JOIN mdl_context ctx ON ctx.id = ra.contextid AND ctx.contextlevel = 30
JOIN mdl_user child ON child.id = ctx.instanceid
WHERE role.shortname = 'parent'
I have not tested that, so there may be typos, but it is about right.