Topic on Talk:Quarry

Looking for templates' names table

3
Summary by BDavis (WMF)

Templates are also pages in the page table. The tl_namespace and tl_title columns are pointers back to the page_namespace and page_title columns of the page table. The "Template" namespace is namespace 10. So if you wanted to find pages in the main namespace that transclude the Template:Table_style template:

USE enwikisource_p;
SELECT page_title
FROM templatelinks
LEFT JOIN page ON (tl_from = page_id AND tl_from_namespace = page_namespace)
WHERE tl_namespace = 10
  AND tl_title = 'Table_style'
  AND tl_from_namespace = 0;
Ineuw (talkcontribs)

I am trying to extract pages in Wikisource which contain a particular template. I have the page table, the templatelinks table, but can't find the table which stores the template names.

BDavis (WMF) (talkcontribs)

Templates are also pages in page table. The tl_namespace and tl_title columns are pointers back to the page_namespace and page_title columns of the page table. The "Template" namespace is namespace 10. So if you wanted to find pages in the main namespace that transclude the Template:Table_style template:

USE enwikisource_p;
SELECT page_title
FROM templatelinks
LEFT JOIN page ON (tl_from = page_id AND tl_from_namespace = page_namespace)
WHERE tl_namespace = 10
  AND tl_title = 'Table_style'
  AND tl_from_namespace = 0;
Ineuw (talkcontribs)

Much thanks, I guess you saw me struggling with it. :-)