 INNER JOIN domains T60 ON T78.domain_id = T60.id
 INNER JOIN sites T259 ON T78.site_id = T259.id
 LEFT JOIN hist_groups T84 ON T78.id = T84.group_id
-LEFT JOIN next_gen_permissions T120 ON T78.id = T120.grantee_id AND next_gen_permissions.next_gen_permissions.grantee_type = 'Group'
+LEFT JOIN next_gen_permissions T120 ON T78.id = T120.grantee_id AND T120.T120.grantee_type = 'Group'
 LEFT JOIN permissions_templates T126 ON T78.id = T126.grantee_id AND permissions_templates.grantee_type = 'Group'
 ---------------------------------------------------
 -- Table hist_capabilities

INNER JOIN data_alerts T47 ON T297.id = T47.view_id
LEFT JOIN hist_views T92 ON T297.id = T92.view_id
INNER JOIN http_requests T97 ON T297.view_url = T97.currentsheet
LEFT JOIN next_gen_permissions T120 ON T297.id = T120.authorizable_id AND next_gen_permissions.authorizable_type = 'View'
INNER JOIN sheet_images T251 ON T297.id = T251.view_id
INNER JOIN user_default_customized_views T284 ON T297.id = T284.view_id
INNER JOIN view_metrics_aggregations T293 ON T297.id = T293.view_id

projects T227
INNER JOIN datasources T55 ON T227.id = T55.project_id
LEFT JOIN hist_projects T86 ON T227.id = T86.project_id
LEFT JOIN next_gen_permissions T120 ON T227.id = T120.authorizable_id AND T120.authorizable_type = 'Project'
INNER JOIN permissions_templates T126 ON T227.id = T126.project_id
INNER JOIN users T290 ON T227.owner_id = T290.id
INNER JOIN sites T259 ON T227.site_id = T259.id
