select distinct pcm.Id, pcm.ContextId, pgum.SubjectId SubjectId, pcm.Permissions, pcm.IsBuiltin, 10 SubjectType, pcm.Created, pcm.Modified from PermissionGroupUserMapping as pgum left join PermissionGroups as pg on (pgum.PermissionGroupId = pg.Id)
left join PermissionContextMapping as pcm on (pg.Id = pcm.SubjectId)
union
select pcm.Id, pcm.ContextId, pcm.SubjectId, pcm.Permissions, pcm.IsBuiltin, 5 SubjectType, Created, Modified from PermissionContextMapping pcm

--group by pcm.ContextId, pcm.SubjectId, pcm.Permissions

