Wikibase/Indexing/SPARQL Query Examples

Syntax according to ../RDF Dump Format/. See also T86786

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

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.

WDQ queries: d:Wikidata:List of queries

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 Dump Format/

People whom we know we don't know their gender
Demonstrates "unknown value" handling.

Humans without children
Demonstrates "no value" handling.

Showcase Queries
These queries show the power and functionality of SPARQL and WDQS GUI.

Overall causes of death ranking

 * Features used:

WWII battle durations

 * Features used:

Children of Genghis Khan

 * Features used:

Music genres

 * Features used:

Airports within 100km of Berlin

 * Features used:

Airports in Belgium

 * Features used:

Schools between San Jose, CA and Sacramento, CA

 * Features used: ,

Locations of national parks

 * Features used:

Map of U1 subway stations in Berlin

 * Features used:

Locations of universities in Germany

 * Features used:

Distribution of names of human settlements ending in "-ow" or "-itz" in Germany

 * Features used:

Locations of power stations

 * Features used:

Locations of stone arch bridges

 * Features used:

Locations of aqueducts

 * Features used:

Locations of archaelogical sites

 * Features used:

Locations of castles that are also archaeological sites

 * Features used:

Locations of battles

 * Features used:

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

 * Features used:

All ski resorts with coordinates

 * Features used:

Lighthouses in Norway

 * Features 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.

Rock bands that start with "M"

 * Items used:
 * Properties used:

Winner of the Academy Awards by Award and Time

 * Items used:
 * Properties used:

Academy award data

 * items used:
 * Properties used:

Number of handed out academy awards per award type

 * Items used:
 * Properties used:

Film directors ranked by number of sitelinks multiplied by their number of films

 * Items used:
 * Properties used:

The Simpsons television series episodes list by season

 * Items used:
 * Properties used:

Pokemon!

 * Items used:
 * Properties used:

Law & Order episodes

 * Items used:
 * Properties used:

Main subjects of West Wing episodes

 * Items used:
 * Properties used:

Movies with Bud Spencer

 * Items used:
 * Properties used:

Popular television series (in treeview)

 * Items used:
 * Properties used:
 * Features used:

Fictional subjects of the Marvel Universe

 * Items used:
 * Properties:

List of present-day countries and capital(s)

 * Items used:
 * Properties used: ,

Largest cities per country

 * Items used:
 * Properties used:

Wikidata people per million inhabitants for all EU countries

 * Items used:
 * Properties used:

Papers about wikidata

 * Items used:
 * Properties used:

Countries sorted by population

 * Items used:
 * Properties used:

Former capitals

 * Properties used:

Largest cities of the world

 * Items used:
 * Properties used:
 * Features used:

Cities connected to Paramaribo (Suriname) by main roads
{{SPARQL2 SELECT DISTINCT ?connection ?connectionLabel ?connectedWith ?connectedWithLabel ?coor WHERE { VALUES ?city {wd:Q3001} # wd:Q3001 = Paramaribo} ?connection wdt:P2789+ ?city ; wdt:P2789+ ?connectedWith. ?connectedWith wdt:P625 ?coor. SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } }}
 * query =
 * 1) defaultView:Map

Longest rivers

 * Items Used:
 * Properties used: ,
 * Features used:

Body of water with the most watercourses ending in it

 * Items used: None
 * Properties used:

Mountains, with coordinates, not located on Earth

 * Items used:
 * Properties used:

Highest mountains in the universe

 * Items used: None
 * Properties used:

Italian mountains higher than 4000mt

 * Items used:
 * Properties used :

Metro stations in Paris

 * Items used:
 * Properties used:

Map of Broadway venues

 * Items used:
 * Properties used:

How many states this US state borders

 * Items used:
 * Properties used: ,

Places that are below 10 meters above sea level

 * Items used:
 * Properties used:

Places within 1km of the Empire State Building

 * Items used:
 * Properties used:

Select French municipalities by INSEE code (select by identifier)

 * Properties used:

Emergency numbers by population using them

 * Items used :
 * Properties used:

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

 * Items used:
 * Properties used:

Popular names per birthplace

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

Map of places mentioned in travel stories with text in French accessible online

 * Items used:
 * Properties used:

Things located where the equator meets the prime meridian

 * Items used:
 * Properties used:

Gender balance of members of Irish parliament

 * Items used:
 * Properties used:

Assemblies by number of seats

 * Items used:
 * Properties used:

List of countries by age of the head of government

 * Items used:
 * Properties used:

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

 * Items used:
 * Properties used:

Members of the French National Assembly born out of France

 * Items used:
 * Properties used:

List of parliament buildings with pictures by country

 * Features used:

Map of places of birth of economists

 * items used:
 * Properties used:

Mathematical proofs

 * Items used:
 * Properties used:

Library and Information Science journals

 * items used:
 * Properties used:

Databases listed in Wikidata and if available applicable licenses

 * Items used:
 * Properties used:

Scientists who have worked together but whose Erdős numbers don’t reflect that

 * Items used:
 * Properties used:

Fictional universes with most fictional planets

 * Items used:
 * Properties used:

Objects with most mass

 * Items used:
 * Properties used:

Biological databases listed in Wikidata and if available applicable licenses

 * Items used:
 * Properties used:

The number of existing translations for diseases in Wikidata
Items used:

A network of Drug-disease interactions on infectious diseases Source: Disease Ontology, NDF-RT and ChEMBL

 * Items used:
 * Properties used:

Who discovered the most asteroids?

 * Items used:
 * Properties used: ,

Who discovered the most planets? (with list)

 * Items used:
 * Properties used:, ,

List of space probes with pictures

 * Features used:

American universities founded before the states they reside in were created

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

Number of scientists per gender

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

Most eponymous mathematicians

 * Items used:
 * Properties used:

Authors of scientific articles by occupation

 * Items used:
 * Properties used:
 * Features used:

Using VALUES for extracting scientific articles of specific authors

 * Items used:
 * Properties used:

Female scientists with most number of sitelinks (but not English Wikipedia)

 * Items used:
 * Properties used:

number of statements backed by a reference with a DOI

 * Items used: None
 * Properties used: None

Translations of the Disease Ontology term DOID:399 (Tuberculosis)

 * Items used:
 * Properties 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: ,
 * Features used:

Politicians who died of cancer (of any type)

 * Items used: ,
 * Properties used:, ,

List of popes

 * Items used:
 * Properties used:

Years with 3 popes

 * Items used:
 * Properties used:

Popes with children

 * Items used:
 * Properties used:

French heads of government by length of service

 * Items used:
 * Properties used:

List of countries in 1754

 * Items used:
 * Properties used:, ,

Population in Europe after 1960

 * Items used:
 * Properties used:

Locations of air accidents

 * Items used:
 * Properties used:

Most prolific fathers

 * Properties used:

People who died by burning - on a timeline

 * Items used:
 * Properties used:

People who lived in the same period as another person

 * Items used:
 * Properties used:

Find drugs for cancers that target genes related to cell proliferation
Items used:

Most common Zika author

 * Items used: ,
 * Properties used:

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

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

 * Items used:, ,
 * Properties used:

Parent taxons of Blue Whale

 * Items used:
 * Properties used:
 * Features used:

taxons and what they are named after

 * Items used: {Q|Q16521|taxon}}
 * Properties used:

Biologists with Twitter accounts

 * Items used:
 * Properties Used:

List of pharmaceutical drugs with picture

 * Items used:
 * Properties used:

Organisms that are located in the female urogential tract and that have a gene with product indole

 * Items used:
 * Properties used:

List of computer files formats

 * Items used:
 * properties used:

List of W3C standards

 * Items used:
 * Properties used:

Oldest software

 * Items used:
 * Properties used:

Universities of main programming language authors

 * Items used:
 * Properties used:

Chemical elements and their properties

 * Items used:
 * Properties used:

Chemical elements and their isotopes by number of neutrons (min/max)

 * Items used:
 * Properties used:

Colors of chemical compounds

 * Items used:
 * Properties used:

All pKa data in Wikidata and the source titles

 * Items used:
 * Properties used:

All CAS registry numbers in Wikidata

 * Properties used:

Chemical compounds in Wikidata sharing the same CAS registry number

 * Properties used:

The number of Chemical compounds in Wikidata sharing the same CAS registry number

 * Properties used:

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

 * Features used:

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

 * Items used:
 * Properties used:

Birthplaces of German Poets

 * Items used:
 * Properties used:

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

 * Items used:
 * Properties used:

Books by a given Author including genres, series, and publication year

 * 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:

Poets and monarchs

 * items used:
 * Properties used:

List of digital libraries in the world

 * Items used:
 * Properties used:

Most popular tonality

 * Properties used:

Music composers by birth place

 * Items used:
 * Properties used:

Composers and their most-used tonality

 * Properties used:

Songs with longest melody

 * Items used: none
 * properties used:

How many musicians dies at certain age

 * Items used:
 * Properties used:

Cathedrals in Paris

 * Items used:
 * Properties used:

Public art in Paris

 * Items used:
 * Properties used:

{{SPARQL|query= SELECT DISTINCT ?item (SAMPLE (?titleL) AS ?title) (group_concat(distinct ?creatorL ; separator = ", ") as ?creator) (group_concat(distinct ?genreL ; separator = ", ") as ?genre) (group_concat(distinct ?placeL ; separator = ", ") as ?place) (group_concat(distinct ?arr ; separator = ", ") as ?arrondissement) (SAMPLE (?img) AS ?image) (SAMPLE (?coord) AS ?coordinates) { SELECT ?item ?titleL ?creatorL ?genreL ?placeL ?arr ?img ?coord WHERE { # selecting items... {     # items in Paris...      ?item wdt:P131 wd:Q90. } UNION { # ...or in an arrondissement of Paris ?item wdt:P131/wdt:P131* wd:Q90. }   # genre: public art ?item wdt:P136 wd:Q557141. # creators OPTIONAL { ?item wdt:P170 ?c. ?c rdfs:label ?creatorL filter (lang(?creatorL) = "fr"). }   #genre OPTIONAL { {       ?item wdt:P136 ?g. FILTER ( STR(?g) != 'http://www.wikidata.org/entity/Q557141') } UNION { ?item wdt:P31 ?g. }     ?g rdfs:label ?genreL filter (lang(?genreL) = "fr"). }   # place OPTIONAL { ?item wdt:P276 ?p. ?p rdfs:label ?placeL filter (lang(?placeL) = "fr"). }   # arrondissement OPTIONAL { ?item wdt:P131 ?a. ?a wdt:P131 wd:Q90. ?a rdfs:label ?arrL filter (lang(?arrL) = "fr"). BIND(REPLACE(?arrL, '^([0-9]+).*$', "$1", "si") AS ?arr) } }}

Works of art where the name might be a rhyme

 * Items used:
 * Properties used:

Works of art where the title is an alliteration

 * Items used:
 * Properties used:

Distribution of public art by place

 * Items used:
 * Properties used:

Birthplaces of Europeana280 artists

 * Items used:
 * Properties used:

Common phrases

 * Items used:
 * Properties used:

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

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

What is the relation between Terrell Buckley and Miami Dolphins?

 * Items used: ,

Women mushers

 * Items used:
 * Properties used:

The awards received by Cristiano Ronaldo and filtered by only the year instead of the default format (i.e. show all of the date information)

 * Items used:
 * Properties used:

Queries for maintenance
These queries help to maintain the data quality of Wikidata. Note that some of these queries may return no results, it's OK - this means the data is correct, as such queries are meant to detect errors.

Disease items with redirected values
This query checks for existing redirects in disease statements. Regularly, the ProteinBoxBot synchronizes Disease items in Wikidata with the disease ontology. This query checks for statement value that got redirected to another Wikidata item.


 * Expected results: 0 items. >0 items requires manual inspection.


 * Properties used:

Disease items with statements capturing Disease Ontology IDs that haven't been update for more then a month
ProteinBoxBot regularly synchronizes disease related items in Wikidata with the disease ontology. This query returns all modification dates ?date_update to less then a month.


 * Expected results: All update dates older then one month require manual inspection by a curator.

Items on human genes that haven't been update for more then a month

 * Expected results: All update dates older then one month require manual inspection by a curator.

Find duplicate IMDB identifiers

 * Properties used:

People born before year 1880 with no death date

 * Items used:
 * Properties used:, ,

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

 * Items used:
 * Properties used:

Objects that have globe which does not match their coordinates

 * Properties used: ,

Aliases of properties which are used more than once

 * Items used: none
 * Properties used: all

Actresses without a description in Spanish

 * items used:
 * Properties used:

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

 * Items used: ,
 * Properties used: ,

Actors whose Spanish label ends with “ (actor)”

 * Items used: ,
 * Properties used: ,

Person labels containing parentheses

 * Items used:
 * Properties used:

Instances of weapon

 * Items used:
 * Properties used: ,

Non-integer populations

 * Properties used:

Odd countries

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

Paintings on taxons

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

Items that are simultaneously instance and subclass of the same class

 * Properties used: ,

Items with specific picture
Note that URL of the filename must be URL encoded.
 * Properties used:

Language statements that point to a country
These language statements point to a country instead of a language, which is almost certainly a mistake. In certain languages, a country and its language may have the same label.
 * Items used:
 * Properties used:, , , , , , ,

People with statements where start and end time are over 100 years apart
It is rare that a statement for a person is actually valid for over 100 years; most of the results are errors (often simple typos in the year).
 * Items used:
 * Properties used:, ,

Human gene items with unreferenced statements
This query returns the number of times a given property exists with in a human gene item without references backing that statement.
 * Items used:
 * Properties used: ,

Capitals that aren’t capitals
This query returns items that are instances of capital but not the capital of any item.
 * Items used:
 * Properties used:, , , ,

Chemical compounds with no CAS registry number

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

Human settlements that are not described in the English WIkipedia

 * Items used:


 * Properties used: ,

Human settlements not being described in any language version of Wikipedia

 * Items used:


 * Properties used: ,

Properties, their labels, descriptions and if they exist of which they are a subproperty
Description: This query returns a table with all properties and if they exist their subproperties

Animals owned by people holding any position

 * Items used:
 * Properties used: