The query editor¶
The query editor at /query is the place to try SPARQL. It has a
code editor with syntax highlighting, a box to choose the profile, and a
results table.
Running a query¶
- Choose the profile to query. Start typing its name or title and pick it
from the list. The box shows the address the query goes to
(
/sparql/<key>). - Type or paste a query.
- Press Run query, or Ctrl+Enter (Cmd+Enter on a Mac).
The status line shows the number of rows and how long the query took.
Try it with the Wikidata profile:
# Paintings by Johannes Vermeer, oldest first
SELECT ?painting ?paintingLabel ?year WHERE {
?painting wdt:P170 wd:Q41264 ;
wdt:P31 wd:Q3305213 .
OPTIONAL { ?painting wdt:P571 ?date . BIND(YEAR(?date) AS ?year) }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?year
Reading the results¶
- SELECT queries give a table. IRIs are links to the
entity viewer, in the same profile. Long values are
shortened; hover to see all of it. Language tags are shown after the text
(for example
@en). - ASK queries show
trueorfalse. - CONSTRUCT and DESCRIBE queries show the returned RDF as text.
- Errors from the endpoint (a syntax error, a timeout) appear in red, with the HTTP status.
Sharing a query¶
The address in the browser's address bar always contains the current query and profile, for example:
/query?profile=479c34c9a197&query=SELECT%20...
Copy it to share the query, or put it in a link. Without profile, the default
profile is used. The ▶ links on SPARQL examples in the documentation
work the same way.
More examples to try¶
How many paintings Wikidata has for five painters of the Dutch Golden Age:
SELECT ?painter ?painterLabel ?paintings WHERE {
{
SELECT ?painter (COUNT(?painting) AS ?paintings) WHERE {
VALUES ?painter { wd:Q5598 wd:Q41264 wd:Q167654 wd:Q205863 wd:Q314889 }
?painting wdt:P170 ?painter ; wdt:P31 wd:Q3305213 .
}
GROUP BY ?painter
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?paintings)
Does the Rijksmuseum have a painting by Vermeer?
ASK { ?painting wdt:P170 wd:Q41264 ; wdt:P195 wd:Q190804 . }
Everything Wikidata says about The Night Watch, as RDF:
CONSTRUCT { wd:Q219831 ?p ?o } WHERE { wd:Q219831 ?p ?o }