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
Certes
.
Toggle Highlighting
SQL
WITH search AS (SELECT "Apple" AS article, "Fruit_trees" AS category) SELECT P1.page_title AS article, 1 AS depth, CONCAT(CL1.cl_to) AS categories FROM search S, page P1 JOIN categorylinks CL1 ON CL1.cl_from=P1.page_id AND CL1.cl_to=S.category WHERE P1.page_namespace=0 AND P1.page_title=S.article UNION SELECT P1.page_title AS article, 2 AS depth, CONCAT(CL1.cl_to, ", ", CL2.cl_to) AS categories FROM page P1 JOIN categorylinks CL1 ON CL1.cl_from=P1.page_id JOIN page P2 ON P2.page_title = CL1.cl_to AND P2.page_namespace=14 JOIN categorylinks CL2 ON CL2.cl_from=P2.page_id AND CL2.cl_to="Fruit_trees" WHERE P1.page_namespace=0 AND P1.page_title="Apple" UNION SELECT P1.page_title AS article, 3 AS depth, CONCAT(CL1.cl_to, ", ", CL2.cl_to, ", ", CL3.cl_to) AS categories FROM page P1 JOIN categorylinks CL1 ON CL1.cl_from=P1.page_id JOIN page P2 ON P2.page_title = CL1.cl_to AND P2.page_namespace=14 JOIN categorylinks CL2 ON CL2.cl_from=P2.page_id JOIN page P3 ON P3.page_title = CL2.cl_to AND P3.page_namespace=14 JOIN categorylinks CL3 ON CL3.cl_from=P3.page_id AND CL3.cl_to="Fruit_trees" WHERE P1.page_namespace=0 AND P1.page_title="Apple" UNION SELECT P1.page_title AS article, 4 AS depth, CONCAT(CL1.cl_to, ", ", CL2.cl_to, ", ", CL3.cl_to, ", ", CL4.cl_to) AS categories FROM page P1 JOIN categorylinks CL1 ON CL1.cl_from=P1.page_id JOIN page P2 ON P2.page_title = CL1.cl_to AND P2.page_namespace=14 JOIN categorylinks CL2 ON CL2.cl_from=P2.page_id JOIN page P3 ON P3.page_title = CL2.cl_to AND P3.page_namespace=14 JOIN categorylinks CL3 ON CL3.cl_from=P3.page_id JOIN page P4 ON P4.page_title = CL3.cl_to AND P4.page_namespace=14 JOIN categorylinks CL4 ON CL4.cl_from=P4.page_id AND CL4.cl_to="Fruit_trees" WHERE P1.page_namespace=0 AND P1.page_title="Apple" UNION SELECT P1.page_title AS article, 5 AS depth, CONCAT(CL1.cl_to, ", ", CL2.cl_to, ", ", CL3.cl_to, ", ", CL4.cl_to, ", ", CL5.cl_to) AS categories FROM page P1 JOIN categorylinks CL1 ON CL1.cl_from=P1.page_id JOIN page P2 ON P2.page_title = CL1.cl_to AND P2.page_namespace=14 JOIN categorylinks CL2 ON CL2.cl_from=P2.page_id JOIN page P3 ON P3.page_title = CL2.cl_to AND P3.page_namespace=14 JOIN categorylinks CL3 ON CL3.cl_from=P3.page_id JOIN page P4 ON P4.page_title = CL3.cl_to AND P4.page_namespace=14 JOIN categorylinks CL4 ON CL4.cl_from=P4.page_id JOIN page P5 ON P5.page_title = CL4.cl_to AND P5.page_namespace=14 JOIN categorylinks CL5 ON CL5.cl_from=P5.page_id AND CL5.cl_to="Fruit_trees" WHERE P1.page_namespace=0 AND P1.page_title="Apple"
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...