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

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/

Cats

 * Items used:

Horses

 * Items used:
 * Properties used:

Recent Events

 * Items used:
 * Properties used:

Popular eye colors

 * Items used: None
 * Properties used:

Even more cats, with pictures

 * Items used:
 * Features used:

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

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

Popular surnames among humans

 * Items used:
 * Properties used:

Given names with most variations

 * Items used:
 * Properties used:

Popular surnames among fictional characters

 * Items used:
 * Properties used:

Women with most sitelinks and no image born in 1921 or later

 * Items used:
 * Properties used:

Overall causes of death ranking

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

WWII battle durations

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

Children of Genghis Khan

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

Music genres

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

Airports within 100km of Berlin

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

Schools between San Jose, CA and Sacramento, CA

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

Whose birthday is today?

 * Properties used:

Finding John and Sarah Connor

 * Items used:
 * Properties used:

Data of Douglas Adams

 * Items used:
 * Properties used:

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: {Q|Q3966183|Pokémon species}}
 * 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:

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 :

Former capitals

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

Continents

 * items used:
 * Properties used:

Some other continents

 * Items used: None
 * Properties used:

Places with continent Antarctica more than 3000 km north of south pole

 * Items used:
 * Properties used:

Places that are below 10 meters above sea level

 * Items used:
 * Properties used:

Largest cities of the world

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

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:

inventors killed by their own invention

 * items used: None
 * 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:

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

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:

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:

Popes with children

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

Museums in Brittany
Tags:

All museums in Barcelona with coordinates

 * Items used:
 * Properties used:

Cathedrals in Paris

 * Items used:
 * Properties used:

Public art in pairs

 * 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) } }}

Locations of Pablo Picasso works

 * Items used:
 * Properties used:

German breweries

 * Items used:
 * Properties used:

Sculptures by Max Bill

 * Items used:
 * Properties used:

Works of art where the name might be a rhyme

 * Items used:
 * Properties used:

Distribution of public art by place

 * Items used:
 * Properties used:

Works of art where the title is an alliteration

 * Items used:
 * Properties used:

Eiffel Tower in art

 * Items used:
 * Properties used:

Songs with longest melody

 * Items used:
 * Properties used:

Birthplaces of Europeana280 artists

 * Items used:
 * Properties used:

Female artists

 * Items used:
 * Properties used:

Paintings by Gustav Klimt

 * Items used: ,
 * Properties used:, ,

Map of all the paintings for which we know a location with the count per location

 * Items used:
 * Properties used:

Versions of The Scream

 * Items used :
 * Properties used:

Depicted objects in art work

 * Properties used:

Public sculptures in Paris

 * Items used:
 * Properties used:

Women who are artists

 * Items used:
 * Properties:

Characters portrayed by most actors

 * Items used: none
 * Properties used:

List of theatre plays

 * Items used:
 * Properties used:

Common phrases

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

What is depicted in artwork

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

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:

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.

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

List of space probes with pictures

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

List of parliament buildings with pictures by country

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

buildings in more than one country

 * Items used:
 * Properties used:

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

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

Files used as “image” in more than 10 items

 * Items used: None
 * Properties used:

Samples with coordinates to illustrate maps

 * Items used:
 * Properties used:

Locations of national parks

 * Features used:

Places with free wifi

 * Items used:
 * Properties used:

Map of U1 subway stations in Berlin

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

Locations of universities in Germany

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

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

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

Locations of power stations

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

Locations of stone arch bridges

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

Locations of aqueducts

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

Locations of archaelogical sites

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

Locations of castles that are also archaeological sites

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

Locations of battles

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

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

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

All ski resorts with coordinates

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

Lighthouses in Norway

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

List of torture devices

 * Items used:
 * Properties used:

Number of jurisdictions by driving side

 * Items used: None
 * Properties used: {Q|P1622|driving side}}

Average lifespan by occupation

 * Items used:
 * Properties used:

Items with the most birth dates

 * Properties used:

Things/people with most children

 * Items used : None
 * Properties used:

French communes with names ending in ac

 * 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

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

Animals owned by people holding any position

 * Items used:
 * Properties used:

Animals that were executed

 * Items used:
 * Properties used:

most frequent occupations without a label in a given language

 * Items used: None
 * Properties used:

Birthplaces of astronauts

 * Items used:
 * Properties used:

Sandwich ingredients

 * Items used:
 * Properties used: