Fork of
Untitled query #91417
by Hadithfajri
This query is marked as a draft
This query has been published
by Hadithfajri.
SQL
AخA
-- Find categories not directly or indirectly linked to Category:Category
SELECT
p.page_title AS "Orphaned Category"
FROM page p
-- Check for direct linkage to Category:Category
LEFT JOIN categorylinks cl_root
ON p.page_id = cl_root.cl_from
AND cl_root.cl_to = 'Category'
AND cl_root.cl_type = 'subcat'
-- Check for indirect linkage via 1 intermediate category
LEFT JOIN categorylinks cl_indirect
ON p.page_id = cl_indirect.cl_from
AND cl_indirect.cl_type = 'subcat'
LEFT JOIN page p_indirect
ON cl_indirect.cl_to = p_indirect.page_title
AND p_indirect.page_namespace = 14
LEFT JOIN categorylinks cl_indirect_root
ON p_indirect.page_id = cl_indirect_root.cl_from
AND cl_indirect_root.cl_to = 'Category'
WHERE
p.page_namespace = 14 -- Category namespace
AND p.page_title != 'Category' -- Exclude root
AND cl_root.cl_from IS NULL -- No direct link to root
AND cl_indirect_root.cl_from IS NULL -- No indirect link via 1 intermediate
LIMIT 5000;
By running queries you agree to the Cloud Services Terms of Use and you irrevocably agree to release your SQL under CC0 License.
All SQL code is licensed under CC0 License.