Wikibase/Indexing/SPARQL Query Examples

Syntax according to RDF Dump format. See also https://phabricator.wikimedia.org/T86786

Further examples can be found at d:Wikidata:SPARQL query service/queries

This page is parsed by the web interface of the query service to fill its drop down of example queries. Keywords in the line below the header are used to be populate the keyword cloud.

Consider adding a comment in the query noting what it illustrates, when and by whom it was written and which are its limitations given the current data and use of properties at Wikidata.

Standard Prefixes
These are standard prefixes, however their use is optional as the query endpoint knows to resolve standard prefixes automatically. PREFIX wd:  PREFIX wdt:  PREFIX wikibase:  PREFIX p:  PREFIX ps:  PREFIX pq:  PREFIX rdfs: 

Simple Queries
These queries help to understand SPARQL and the Wikibase RDF format

Cats

 * Items used:

Showcase Queries
These queries show the power and functionality of query.wikidata.org.

Databases listed in Wikidata and if available applicable licenses
Items used:

Biological databases listed in Wikidata and if available applicable licenses
Tags:

Find the number of existing translations for diseases in Wikidata
Items used:

Museum
Tags:

Queries for maintenance
These queries help to maintain the data quality of Wikidata

Find duplicate identifiers

 * Items used:
 * Properties used:

= Unsorted =

Even more cats

 * Items used:

US presidents and spouses

 * Items used:
 * Properties used: ,

List of presidents with causes of death

 * Items used:
 * Properties used: ,

Presidents and their causes of death ranking

 * Items used:
 * Properties used: ,

Politicians who died of cancer (of any type)

 * Items used: ,
 * Properties used:, ,

People born before year 1880 with no death date

 * Items used:
 * Properties used:, ,

Largest cities with female mayor

 * Items used: ,
 * Properties used:, , , , ,

List of countries ordered by the number of their cities with female mayor

 * Items used: ,
 * Properties used:, , , , ,

List of present-day countries and capital(s)

 * Items used:
 * Properties used: ,

How many states this US state borders

 * Items used:
 * Properties used: ,

Whose birthday is today?

 * Properties used:

Who discovered the most asteroids?

 * Items used:
 * Properties used: ,

Who discovered the most planets? (with list)

 * Items used:
 * Properties used:, ,

American universities founded before the states they reside in were created

 * Items used:.
 * Properties used:, , , ,

What is the relation between Terrell Buckley and Miami Dolphins?

 * Items used: ,

Properties that are defined as "qualifier only" but are used in references

 * Items used:
 * Properties used:

Aliases of properties which are used more than once

 * Items used: none
 * Properties used: all

WDQ queries: https://www.wikidata.org/wiki/Wikidata:List_of_queries

List of space probes with pictures

 * Items used:
 * Properties used: ,

List of parliament buildings with pictures by country

 * Items used:
 * Properties used:, ,

List of actors with pictures with year of birth and/or death

 * Items used: ,
 * Properties used:, , , ,

French people with an article on the English Wikipedia but not on the French one

 * Items used: ,
 * Properties used: ,

Number of scientists per gender

 * Items used: ,
 * Properties used:, , ,

Mushers with neither a ranking in a race nor a reason for not finishing it

 * Items used:
 * Properties used:, , , , ,

Number of ministers who are themselves children of a minister, per country

 * Items used:
 * Properties used:

Winner of the Academy Awards by Award and Time

 * Items used:
 * Properties used:

Actresses without a description in Spanish

 * items used:
 * Properties used:

Academy award data

 * items used:
 * Properties used:

Paintings by Gustav Klimt

 * Items used: ,
 * Properties used:, ,

Number of handed out academy awards per award type

 * Items used:
 * Properties used:

Birthplaces of German Poets

 * Items used:
 * Properties used:

Authors, writers and poets ranked by sitelink and also includes "country of citizenship".

 * Items used:
 * Properties used:

Orders "instances of" "books" with an author by "site link"

 * Items used:
 * Properties used:

Books or literary works published before 1830 with place of publication or narrative location coordinates

 * Items used:
 * Properties used:

Place of publication unbound

 * Properties used:

Birthplace of composers

 * Items used:
 * Properties used:

Samples with coordinates to illustrate maps

 * Items used:
 * Properties used:

Map of U1 subway stations in Berlin

 * Items used:
 * Properties used:

Locations of universities in Germany

 * Items used:
 * Properties used:

Locations of power stations

 * Items used:
 * Properties used:

Locations of stone arch bridges

 * Items used:
 * Properties Used:

Locations of aqueducts

 * Items used:
 * Properties used:

Locations of archaelogical sites

 * Items used:
 * Properties used:

Locations of castles that are also archaeological sites

 * Items used:
 * Properties used:

Locations of battles

 * Items used:
 * Properties used:

Locations of Pablo Picasso works

 * Items used:
 * Properties used:

All museums (including subclass of museum) in Washington, D.C. with coordinates

 * Items used:
 * Properties used:

All ski resorts with coordinates

 * Items used:
 * Properties used:

Lighthouses in Norway

 * Items used:
 * Properties used:

Mountains, with coordinates, not located on Earth

 * Items used:
 * Properties used:

Literary Works by Label Count

 * Items used:
 * Properties used:

All subclasses of "Literary Work"

 * Items used:
 * Properties used:

Epic Poems by Label Count

 * Items used:
 * Properties used:

Epic Poems by SiteLink Count

 * Items used:
 * Properties used:

Instance of Book by Sitelink Count

 * Items used:
 * Properties used:

Finding John and Sarah Connor

 * Items used:
 * Properties used:

Gender balance of members of Irish parliament

 * Items used:
 * Properties used:

Most popular tonality

 * Properties used:

List of torture devices

 * Items used:
 * Properties used:

Biologists with Twitter accounts

 * Items used:
 * Properties Used:

Locations of air accidents

 * Items used:
 * Properties used:

French heads of government by length of service

 * Items used:
 * Properties used:

Public sculptures in Paris

 * Items used:
 * Properties used:

Women who are artists

 * Items used:
 * Properties:

Largest cities of the world

 * Items used:
 * Properties used:

Most popular fathers

 * Properties used:

Items with the most birth dates

 * Properties used:

Select French municipalities by INSEE code (select by identifier)

 * Properties used:

The Simpsons television series episodes list by season

 * Items used:
 * Properties used:

Popular television series (in treeview)

 * Items used:
 * Properties used:

Statements from literature (DOI references)
Properties used:

Increasingly the Digital Object Identifier (DOI) is used to identifier literature, though not the only identifier. These example start with the DOI.

Statements originating from a specific DOI
Properties used:

Overall causes of death ranking
Items used: Properties used:

WWII battle durations

 * Items used:
 * Properties used:

Common phrases

 * Items used:
 * Properties used:

Poets and monarchs

 * items used:
 * Properties used:

List of digital libraries in the world

 * Items used:
 * Properties:

List of computer files formats

 * Items used:
 * Properties used:

List of pharmaceutical drugs with picture

 * Items used:
 * Properties used:

List of theatre plays

 * Items used:
 * Properties used:

List of popes

 * Items used:
 * Properties used:

List of W3C standards

 * Items used:
 * Properties used:

Population in Europe after 1960

 * Items used:
 * Properties used:

Publishers by occupation

 * Items used:
 * Properties used:

Data of Douglas Adams

 * Items used:
 * Properties:

Fictional subjects of the marvel universe

 * Properties used:

Depicted objects in art work

 * Items used:
 * Properties used:

Most eponymous mathematicians

 * Items used:
 * Properties used:
 * Uses

Request all organisms that are located in the female urogential tract and that have a gene with product indole
{{SPARQL|query= SELECT ?organism_name WHERE {  	?organism_item wdt:P276 wd:Q5880 ; rdfs:label ?organism_name. ?gene wdt:P703 ?organism_item ; wdt:P1056 wd:Q319541. FILTER (LANG(?organism_name) = "en"). } }}
 * Items used:
 * Properties used:   {{Q|

Request all known translations of the Disease Ontology term DOID:399 (Tuberculosis)
{{SPARQL|query= SELECT ?English ?language ?label WHERE {	?disease wdt:P699 "DOID:399" ; rdfs:label ?English ; rdfs:label ?label. FILTER (LANG(?English) = "en") BIND(LANG(?label) as ?languageCode) ?languageCode ^ps:P424 ?lstatement. ?lstatement pq:P794 wd:Q22283033	; ^p:P424 ?wdLanguage. ?wdLanguage rdfs:label ?language. FILTER (LANG(?language)="en") } }}
 * Items used: {{Q|
 * Properties used: {{Q|P699|Disease Ontology ID}} {{Q|P424|Wikimedia language code}} {{Q|P794|as}}

Airports within 100km of Berlin

 * Items used:
 * Properties used:

Schools between San Jose, CA and Sacramento, CA

 * Uses
 * Items used:
 * Properties used:

Longest rivers

 * Items Used:
 * Properties used: ,

Popular names per birthplace

 * Items used:
 * Properties used: ,

Listeria
Samples suitable for Listeria. Generally only include ?item as output. Listeria will add more information from that item. Additional variables from the query could also be used in the lists.

Women born in Wales without an article in Welsh for Listeria
Properties used:
 * Items used:

People born in Occitania for Listeria

 * Items used:
 * Properties used:

People born in Scotland for Listeria (1)

 * Items used:
 * Properties used:

People born in Scotland for Listeria (2)

 * Items used:
 * Properties used: ,

Occupations with a German label

 * Items used:
 * Properties used:

Chemical elements and their properties

 * Items used:
 * Properties used:

Scientific articles that have subject Zika virus or fever and that are used as a reference in another item

 * Items used:, ,
 * Properties used:

Most common Zika author

 * Items used: ,
 * Properties used:

Wikidata scientific articles that contain "zika" in the title
Applicable Tags: ., ,

Get the available PMID-DOI mappings
Applicable Tags:

Find drugs for cancers that target genes related to cell proliferation
Applicable tags:

Popes with children

 * Items used:
 * Properties used:

Animals owned by people holding any position

 * Items used:
 * Properties used:

Parent taxons of Blue Whale

 * Items used:
 * Properties used:

Children of Genghis Khan

 * Items used:
 * Properties used:

German states, ordered by the number of company headquarters per million inhabitants

 * Items used:
 * Properties used:

This query shows some not-so-easy nesting of DISTINCT (don't count any company twice) and aggregate, in combination with arithmetic output evaluation functions. It is a hard query that may time out if modified.

Wikidata people per million inhabitants for all EU countries

 * Items used:
 * Properties used:

Interesting maintenance query that shows the relative prominence of a country's current (living) population on Wikidata. The query tends to time out when using all countries at once, but it might be possible to get the figures for each individual country by using, e.g., BIND( wd:Q30 AS ?country ) instead of ?country wdt:P31 wd:Q185441 ..