Help:Contributing/query: Difference between revisions

From Wikibase
Jump to navigation Jump to search
Rewrite in code-guide style: strip translation markup, <code> for plain tokens, link the SPARQL cheatsheet (via update-page on MediaWiki MCP Server)
Standardize: add copy button to block code snippets
 
Line 9: Line 9:
All books in the knowledge base:
All books in the knowledge base:


<syntaxhighlight lang="sparql">
<syntaxhighlight lang="sparql" copy>
SELECT ?book ?bookLabel WHERE {
SELECT ?book ?bookLabel WHERE {
   ?book wdt:P1 wd:Q9 .            # instance of (P1) → book (Q9)
   ?book wdt:P1 wd:Q9 .            # instance of (P1) → book (Q9)

Latest revision as of 09:46, 23 August 2026

Languages: English · français · Esperanto

This page shows how to query the knowledge base with SPARQL. Start at the Help:Contributing hub if you are new here.

The endpoint

The public SPARQL endpoint is https://wikibase.ronzz.org/sparql.

A first query

All books in the knowledge base:

SELECT ?book ?bookLabel WHERE {
  ?book wdt:P1 wd:Q9 .            # instance of (P1) → book (Q9)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

The wdt: prefix reads the values of a property; wd: names an entity. On this instance, instance of is P1 and book is Q9.

The Wikidata SPARQL tutorial works verbatim on this instance. For the full syntax reference, see Cheatsheets:SPARQL.

See also