Toggle navigation
Home
New Query
Recent Queries
Discuss
Database tables
Database names
MediaWiki
Wikibase
Replicas browser and optimizer
Login
History
Fork
This query is marked as a draft
This query has been published
by
Polygnotus
.
Toggle Highlighting
SQL
WITH RECURSIVE tree AS ( -- Base case: direct subcategories SELECT DISTINCT cl_from AS id, page_title AS title, 1 AS level FROM categorylinks JOIN page ON cl_from = page_id WHERE cl_to = 'Companies' AND page_namespace = 14 UNION ALL -- Recursive part SELECT DISTINCT cl2.cl_from, p2.page_title, tree.level + 1 FROM categorylinks cl2 JOIN page p2 ON cl2.cl_from = p2.page_id JOIN tree ON cl2.cl_to = CAST(tree.title AS CHAR) WHERE p2.page_namespace = 14 AND tree.level < 5 -- Prevent infinite recursion ) SELECT DISTINCT title, level FROM tree ORDER BY level, title;
By running queries you agree to the
Cloud Services Terms of Use
and you irrevocably agree to release your SQL under
CC0 License
.
Submit Query
Stop Query
All SQL code is licensed under
CC0 License
.
Checking query status...