-- RE details
select
re.id,
concat(case when os.org_id is not null then os.org_id else '*' end, case when os.wildcard = 1 then '+' else '' end) as 'org_spec',
re.path_expr,
re.dynamic_expr,
rb.role_name as 'role',
pb.permission_name as 'permission',
case when g.id is not null then 'GRANTED' else '' end as 'granted'
from
resource_expression re
join org_spec os on os.id = re.org_spec_id
left outer join permission_binding pb on pb.resource_expression_id = re.id
left outer join role_binding rb on rb.resource_expression_id = re.id
left outer join grantz g on g.resource_expression_id = re.id
order by
path_expr,
org_spec;