SELECT resource_category.*,
resource_category.resource_count as resource_count
,
permission.cache_value AS category_permission_cache
FROM xf_resource_category AS resource_category
LEFT JOIN xf_permission_cache_content AS permission
ON (permission.permission_combination_id = 1
AND permission.content_type = 'resource_category'
AND permission.content_id = resource_category.resource_category_id)
ORDER BY resource_category.lft