This website does readability filtering of other pages. All styles, scripts, forms and ads are stripped. If you want your website excluded or have other feedback, use this form.

Wikidata:SPARQL query service/queries/examples - Wikidata

Wikidata:SPARQL query service/queries/examples

From Wikidata < Wikidata:SPARQL query service‎ | queries Jump to navigation Jump to search Translate this page Other languages: Bahasa Melayu • ‎Deutsch • ‎English • ‎Esperanto • ‎Nederlands • ‎català • ‎dansk • ‎español • ‎français • ‎italiano • ‎lietuvių • ‎polski • ‎português do Brasil • ‎svenska • ‎čeština • ‎русский • ‎українська • ‎עברית • ‎العربية • ‎සිංහල • ‎中文 • ‎日本語 • ‎한국어 Warning: Editing this page will change the examples shown on query.wikidata.org Please help to improve this page! Phabricator task T132690 Feel free to add your example, or edit an existing one, if you think it is useful

This page is parsed by the web interface of the query service to fill the query example dialog. Many of the examples also work in template:Wikidata list template calls parsed by the Listerbot, which however requires the ?item field variable to be selected.

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.

Some queries did not fit here because of technical restrictions:

Contents

See also

Simple Queries

These basic queries help to understand SPARQL and the Wikibase RDF format.

Cats

The following query uses these:

  • Properties: instance of (P31)  
    1 SELECT ?item ?itemLabel 
    2 WHERE 
    3 {
    4   ?item wdt:P31 wd:Q146.
    5   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    6 }
    
Try it!

Goats

The following query uses these:

  • Properties: instance of (P31)  
    1 SELECT ?item ?itemLabel 
    2 WHERE 
    3 {
    4   ?item wdt:P31 wd:Q2934.
    5   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    6 }
    
Try it!


Horses (showing some info about them)

#Illustrates optional fields, instances of subclasses, language fallback on label service, date to year conversion
#Horses on Wikidata
SELECT DISTINCT ?horse ?horseLabel ?mother ?father (year(?birthdate) as ?birthyear) (year(?deathdate) as ?deathyear) ?genderLabel
WHERE
{
	?horse wdt:P31/wdt:P279* wd:Q726 .     # Instance et sous-classes de Q726-Cheval
	 
	OPTIONAL{?horse wdt:P25 ?mother .}       # P25  : Mère
	OPTIONAL{?horse wdt:P22 ?father .}       # P22  : Père
	OPTIONAL{?horse wdt:P569 ?birthdate .} # P569 : Date de naissance
	OPTIONAL{?horse wdt:P570 ?deathdate .}     # P570 : Date de décès
	OPTIONAL{?horse wdt:P21 ?gender .}       # P21  : Sexe
 
	SERVICE wikibase:label { #BabelRainbow
		bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr,ar,be,bg,bn,ca,cs,da,de,el,en,es,et,fa,fi,he,hi,hu,hy,id,it,ja,jv,ko,nb,nl,eo,pa,pl,pt,ro,ru,sh,sk,sr,sv,sw,te,th,tr,uk,yue,vec,vi,zh"
	}
}
ORDER BY ?horse

Try it!

Cats, with pictures

The following query uses these:

Features: ImageGrid (Q24515278)  

 1 #added before 2016-10
 2 
 3 #defaultView:ImageGrid
 4 SELECT ?item ?itemLabel ?pic
 5 WHERE
 6 {
 7 ?item wdt:P31 wd:Q146 .
 8 ?item wdt:P18 ?pic
 9 SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
10 }
Try it!

Map of hospitals

The following query uses these:

Features: Map (Q24515275)  

1 #added 2017-08
2 #defaultView:Map
3 SELECT * WHERE {
4   ?item wdt:P31/wdt:P279* wd:Q16917;
5         wdt:P625 ?geo .
6 }
Try it!

Number of humans in Wikidata

Using the count function

SELECT (COUNT(?item) AS ?count)
WHERE {
	?item wdt:P31 wd:Q5 .
}

Try it!

Humans without children

In the simplest form:

The following query uses these:

  • Properties: instance of (P31)  , child (P40)  
    1 #added before 2016-10
    2 #Demonstrates "no value" handling
    3 SELECT ?human ?humanLabel
    4 WHERE
    5 {
    6 	?human wdt:P31 wd:Q5 .       #find humans
    7 	?human rdf:type wdno:P40 .   #with at least one P40 (child) statement defined to be "no value"
    8 	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
    9 }
    
Try it!

An equivalent query (slightly more verbose):

SELECT ?human ?humanLabel 
WHERE
{
  ?human wdt:P31 wd:Q5 .         #find humans
  ?human p:P40 ?childStatement . #with at least one P40 (child) statement
  ?childStatement rdf:type wdno:P40 .   #where the P40 (child) statement is defined to be "no value"
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}

Try it!

Items with a Wikispecies sitelink

#added before 2016-10
#illustrates sitelink selection, ";" notation
SELECT ?item ?itemLabel ?article
WHERE
{
	?article 	schema:about ?item ;
			schema:isPartOf <https://species.wikimedia.org/> .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
LIMIT 200

Try it!

Items about authors with a Wikispecies page

SELECT ?author ?authorLabel (COUNT(?paper) AS ?count)
WHERE
{
	?article 	schema:about ?author ;
			schema:isPartOf <https://species.wikimedia.org/> .
    ?author wdt:P31 wd:Q5.
    ?paper wdt:P50 ?author.
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
GROUP BY ?author ?authorLabel
ORDER BY DESC(?count)
LIMIT 200

Try it!

Recent Events

The following query uses these:

  • Properties: instance of (P31)  , subclass of (P279)  , point in time (P585)  , start time (P580)  
     1 SELECT ?event ?eventLabel ?date
     2 WHERE
     3 {
     4 	# find events
     5 	?event wdt:P31/wdt:P279* wd:Q1190554.
     6 	# with a point in time or start date
     7 	OPTIONAL { ?event wdt:P585 ?date. }
     8 	OPTIONAL { ?event wdt:P580 ?date. }
     9 	# but at least one of those
    10 	FILTER(BOUND(?date) && DATATYPE(?date) = xsd:dateTime).
    11 	# not in the future, and not more than 31 days ago
    12 	BIND(NOW() - ?date AS ?distance).
    13 	FILTER(0 <= ?distance && ?distance < 31).
    14 	# and get a label as well
    15 	OPTIONAL {
    16 		?event rdfs:label ?eventLabel.
    17 		FILTER(LANG(?eventLabel) = "en").
    18 	}
    19 }
    20 # limit to 10 results so we don't timeout
    21 LIMIT 10
    
Try it!

Popular eye colors among humans

#added before 2016-10
#illustrates bubblechart view, count

#defaultView:BubbleChart
SELECT ?eyeColorLabel (COUNT(?human) AS ?count)
WHERE
{
	?human wdt:P31 wd:Q5.
	?human wdt:P1340 ?eyeColor.
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?eyeColorLabel

Try it!

Humans whose gender we know we don't know

The following query uses these:

  • Properties: sex or gender (P21)  
    1 #added before 2016-10
    2 # Demonstrates filtering for "unknown value"
    3 SELECT ?human ?humanLabel
    4 WHERE
    5 {
    6 	?human wdt:P21 ?gender
    7 	FILTER isBLANK(?gender) .
    8 	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
    9 }
    
Try it!

Humans with given name, family name, gender, and ethnic group

#Contributed on 22nd October, 2019 by Shubhanshu Mishra (https://shubhanshu.com)
#Given name, Surname with gender, ethnic_group in any language label
SELECT ?human ?gender ?genderLabel ?ethnic_group ?ethnic_groupLabel ?given_name ?given_nameLabel ?family_name ?family_nameLabel WHERE {
  ?human wdt:P31 wd:Q5;
    wdt:P21 ?gender;
    wdt:P172 ?ethnic_group;
    wdt:P735 ?given_name.
  ?human wdt:P734 ?family_name.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr,ar,be,bg,bn,ca,cs,da,de,el,en,es,et,fa,fi,he,hi,hu,hy,id,it,ja,jv,ko,nb,nl,eo,pa,pl,pt,ro,ru,sh,sk,sr,sv,sw,te,th,tr,uk,yue,vec,vi,zh". }
}

Try it!

URLs of Wikipedia in all languages

This query provides an alternative to scraping the Wikipedia.org portal page and various lists/tables of Wikipedias that are out there. (The sitematrix API is another alternative.)

SELECT ?wikipedia WHERE {
  ?wikipedia wikibase:wikiGroup "wikipedia".
}

Try it!

Names of Wikipedia articles in multiple languages

The query retrieves Wikipedia article names (in the main namespace) in various languages for the given Q identity.

SELECT DISTINCT ?lang ?name WHERE {
  ?article schema:about wd:Q5 ;
              schema:inLanguage ?lang ;
              schema:name ?name ;
              schema:isPartOf [ wikibase:wikiGroup "wikipedia" ] .
  FILTER(?lang in ('en', 'uz', 'ru', 'ko')) .
  FILTER (!CONTAINS(?name, ':')) .
}

Try it!

All items with a property

# Sample to query all values of a property
# Property talk pages on Wikidata include basic queries adapted to each property
SELECT
  ?item ?itemLabel
  ?value ?valueLabel
# valueLabel is only useful for properties with item-datatype
WHERE 
{
  ?item wdt:P1800 ?value
  # change P1800 to another property        
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
# remove or change limit for more results
LIMIT 10

Try it!

Wikidata items of Wikipedia articles

#Returns a list of Wikidata items for a given list of Wikipedia article names
#List of Wikipedia article names (lemma) is like "WIKIPEDIA ARTICLE NAME"@LANGUAGE CODE with de for German, en for English, etc.
#Language version and project is defined in schema:isPartOF with de.wikipedia.org for German Wikipedia, es.wikivoyage for Spanish Wikivoyage, etc.

SELECT ?lemma ?item WHERE {
  VALUES ?lemma {
    "Wikipedia"@de
    "Wikidata"@de
    "Berlin"@de
    "Technische Universität Berlin"@de
  }
  ?sitelink schema:about ?item;
    schema:isPartOf <https://de.wikipedia.org/>;
    schema:name ?lemma.
}

Try it!

Total population in the Øresund Region

The following query uses these:

  • Properties: part of (P361)  , population (P1082)  , instance of (P31)  , has part (P527)  
     1 # by So9q, 2019-11-22
     2 # Total population in the Øresund Region
     3 # Example of the SUM aggregate function
     4 
     5 SELECT distinct ?area ?areaLabel (sum(?folkm_ngd) as ?total_folkm) # the first two variables can be removed
     6                                                                    # if only the number is needed
     7 WHERE {
     8   ?item wdt:P361 wd:Q297853.
     9   ?item wdt:P1082 ?folkm_ngd. 
    10   ?area wdt:P31 wd:Q1907114.
    11   ?area wdt:P527 ?item.
    12   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    13 }
    14 group by ?area ?areaLabel
    
Try it!

Lexeme queries

Lexemes in English that match an expression

The following query uses these:

  • Items: English (Q1860)  
    1 # Lexemes in English that match an expression
    2 select ?lexemeId ?lemma WHERE {
    3   ?lexemeId <http://purl.org/dc/terms/language> wd:Q1860;
    4             wikibase:lemma ?lemma.
    5   # only those lemmas that begin with "pota", i.e. "potato"
    6   FILTER (regex(?lemma, '^pota.*'))
    7 }
    
Try it!

Pictures of noun lexemes in English (picture dictionary à la Wikidata)

The following query uses these:

Features: ImageGrid (Q24515278)  

 1 # Lexemes in English with picture and description fetched from the concept Q-item
 2 # NB: when 2 or more pictures occur for the same lemma a preferred rank is missing on the Q-item. 
 3 # Please fix that if you know how.
 4 # by So9q
 5 #defaultView:ImageGrid
 6 select distinct ?lexemeId ?lemma ?q_concept ?q_conceptDescription ?picture 
 7 WHERE {
 8   ?lexemeId dct:language wd:Q1860;
 9             wikibase:lemma ?lemma;
10             ontolex:sense ?sense.
11   ?sense wdt:P5137 ?q_concept.
12   ?q_concept wdt:P18 ?picture.
13   # if you wish to only browse certain items you can insert a FILTER 
14   # regular expression here, like in the example above.
15   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
16 }
17 order by lcase(?lemma) # order a-z
Try it!

German picture dictionary for young children

The following query uses these:

Features: ImageGrid (Q24515278)  

 1 # German picture dictionary for young children
 2 # NB: when 2 or more pictures occur for the same lemma a preferred rank is missing on the Q-item. 
 3 # Please fix that if you know how.
 4 # If any inapproriate terms show up it is probably because the sense is missing a correct P5137
 5 # by So9q
 6 #defaultView:ImageGrid
 7 select distinct ?lexemeId ?lemma ?q_concept ?q_conceptDescription ?picture 
 8 WHERE {
 9   ?lexemeId dct:language wd:Q188; # change language here
10             wikibase:lemma ?lemma;
11             ontolex:sense ?sense.
12   ?sense wdt:P5137 ?q_concept.
13   ?q_concept wdt:P18 ?picture.
14   ############
15   # Exclusions
16   ############
17   # Exclude out of scope concepts
18   MINUS {?q_concept wdt:P31 wd:Q3624078.}. # countries
19  
20   # Exclude non suitable concepts
21   VALUES ?minus {
22   wd:Q47092 # rape
23   wd:Q198   # war
24   wd:Q124490 # violence
25   wd:Q170382 # revolver
26   wd:Q1576   #cigar
27   #... add yours here
28   }.
29   MINUS {?sense wdt:P5137 ?minus.}.
30   
31   # Exclude senses not suitable for young children:
32   VALUES ?filter {
33   wd:Q8102
34   wd:Q545779
35   wd:Q1521634
36   wd:Q184439}.
37   FILTER NOT EXISTS {?sense wdt:P6191 ?filter.}.
38   # if you wish to only browse certain items you can insert a FILTER 
39   # regular expression here, like in the example above.
40   SERVICE wikibase:label { bd:serviceParam wikibase:language "de,en". }
41 }
42 order by lcase(?lemma) # order a-z
Try it!

Lexeme languages by number of usage examples

The following query uses these:

Features: BubbleChart (Q24515280)  

 1 # Lexeme languages by number of usage examples
 2 # by Vesihiisi
 3 
 4 #defaultView:BubbleChart
 5 SELECT ?languageLabel (COUNT(?example) AS ?count ) WHERE {
 6   ?l a ontolex:LexicalEntry; dct:language ?language.
 7   ?l wdt:P5831 ?example.
 8   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
 9 }
10 GROUP BY ?languageLabel
11 ORDER BY DESC(?count)
Try it!

Lexemes describing a color

The following query uses these:

  • Properties: instance of (P31)  
    1 # Lexemes describing a color
    2 # By Vesihiisi
    3 
    4 SELECT ?l ?lemma ?languageLabel  WHERE {
    5   ?l a ontolex:LexicalEntry; dct:language ?language; wikibase:lemma ?lemma .
    6   ?l wdt:P31 wd:Q376431.
    7   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    8 }
    9 ORDER BY ?languageLabel
    
Try it!

Lexemes that means water ordered by language

The following query uses these:

  • Properties: item for this sense (P5137)  
     1 # By So9q
     2 # Lexemes that means (liquid) water
     3 select ?l ?sense ?lemma ?languageLabel WHERE {
     4   ?l a ontolex:LexicalEntry ; # get from the special LexicalEntry
     5        ontolex:sense ?sense ; # the sense
     6        dct:language ?language ; # the language
     7        wikibase:lemma ?lemma. # and the lemma
     8   ?sense wdt:P5137 wd:Q29053744 .
     9                    # change Q29053744 to anything you want 
    10   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    11 }
    12 order by (LCASE(?languageLabel))
    
Try it!

The 100 most translated concepts in the Lexeme namespace

# by So9q, 2019-11-21
# no known limitations

#defaultView:BubbleChart
SELECT ?meaning ?meaningLabel (count(?l) as ?count) 
WHERE {
   ?l a ontolex:LexicalEntry ; 
        ontolex:sense ?sense. # get the sense
  ?sense wdt:P5137 ?meaning. #extract the meaning
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en"}
}
group by ?meaning ?meaningLabel # 2 here to avoid "bad aggregate", see https://www.wikidata.org/wiki/Wikidata:SPARQL_tutorial#Painting_materials
order by desc(?count) # rank by the most translated concepts 
limit 100 # only show the 100 highest to avoid clutter

Try it!

Demonyms on map

The following query uses these:

Features: Map (Q24515275)  

 1 # Words describing people from a certain place
 2 # e.g. swede
 3 # by Vesihiisi
 4 #defaultView:Map
 5 SELECT ?l ?lemma ?demoPlaceLabel ?coords WHERE {
 6   ?l a ontolex:LexicalEntry ; dct:language ?language ;
 7        wikibase:lemma ?lemma .
 8   ?language wdt:P218 'sv'. # language
 9   ?l ontolex:sense ?sense.
10      ?sense wdt:P6271 ?demoPlace.
11   ?demoPlace wdt:P625 ?coords
12   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
13 }
Try it!

Forms in Hebrew that are both feminine and masculine

The following query uses these:

  • Items: Hebrew (Q9288)  , noun (Q1084)  , masculine (Q499327)  , feminine (Q1775415)  
     1 # Forms of nouns in Hebrew that are both feminine and masculine
     2 # e.g. שמש
     3 # by Uziel302
     4 select ?lexemeId ?lemma ?form1 ?word WHERE {
     5   ?lexemeId <http://purl.org/dc/terms/language> wd:Q9288;
     6             wikibase:lexicalCategory wd:Q1084;
     7             wikibase:lemma ?lemma.
     8   ?lexemeId ontolex:lexicalForm ?form1 .
     9   ?form1 wikibase:grammaticalFeature wd:Q499327;
    10          wikibase:grammaticalFeature wd:Q1775415;
    11          ontolex:representation ?word .
    12 }
    
Try it!

Wikibase predicates

Properties

Properties grouped by their parent property

#Properties grouped by their parent property
#TODO: should display links and numeric ids
#defaultView:Tree
SELECT ?property2 ?property2Label ?property1 ?property1Label WHERE {
  ?property1 rdf:type wikibase:Property. #not replaceable with wikibase:Item, wikibase:Statement, wikibase:Reference at WDQS
                                         #https://www.mediawiki.org/wiki/Wikibase/Indexing/RDF_Dump_Format#WDQS_data_differences
  ?property1 wdt:P1647 ?property2.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

Subproperties of location (P276)

#Subproperties of location (P276)
SELECT DISTINCT ?subProperties ?subPropertiesLabel WHERE {
  ?subProperties wdt:P1647* wd:P276.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

Properties grouped by their Wikibase datatype (Q19798645) with number of properties

#Properties grouped by their type with number of properties
SELECT (COUNT(?property) as ?pcount ) ?wbtype WHERE {
  ?property rdf:type               wikibase:Property.
  ?property wikibase:propertyType  ?wbtype.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?wbtype
ORDER BY DESC(?pcount)

Try it!

Properties with value a technical standard (Q317623)

#Properties with value a technical standard
SELECT DISTINCT ?propertyRel ?propertyItem ?propertyItemLabel WHERE 
{
   ?item ?propertyRel ?standard.
   ?standard wdt:P31 wd:Q317623.
   ?propertyItem wikibase:directClaim ?propertyRel
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!


All properties with descriptions and aliases and types

SELECT ?property ?propertyType ?propertyLabel ?propertyDescription ?propertyAltLabel WHERE {
  ?property wikibase:propertyType ?propertyType .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ASC(xsd:integer(STRAFTER(STR(?property), 'P')))

Try it!

Properties connecting items of type zoo (Q43501) with items of type animal (Q729)

select ?p ?pLabel (count (*) as ?count) {
  ?s ?pd ?o .
  ?p wikibase:directClaim ?pd .
  ?s wdt:P31/wdt:P279* wd:Q729 .
  ?o wdt:P31/wdt:P279* wd:Q43501 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} group by ?p ?pLabel order by desc(?count)

Try it!

References

Content of a reference for a specific statement

The following query uses these:

  • Properties: described by source (P1343)  , section, verse, paragraph, or clause (P958)  
     1 # See also the SPARQL manual
     2 # https://en.wikibooks.org/wiki/SPARQL/WIKIDATA_Qualifiers,_References_and_Ranks
     3 # In this example we look for statements which assign a specific value (Q51955019)
     4 # to the property P1343 and then look for references of that property, specifically
     5 # the string associated to P958 for the reference. May actually bring up references
     6 # for other P1343 statements; uses the shortened expression syntax with brackets.
     7 SELECT ?item ?reference
     8 WHERE {
     9   ?item wdt:P1343 wd:Q51955019 .
    10   ?item p:P1343 [ prov:wasDerivedFrom [ pr:P958 ?reference ] ] .
    11 }
    
Try it!

Wikimedia projects

Sitelinks

See also: Help:Sitelinks

Countries that have sitelinks to en.wiki

The following query uses these:

  • Properties: instance of (P31)  
     1 SELECT ?country ?countryLabel ?article WHERE {
     2 
     3     ?country wdt:P31 wd:Q3624078 . # sovereign state
     4     ?article schema:about ?country .
     5     ?article schema:isPartOf <https://en.wikipedia.org/>.
     6 
     7     SERVICE wikibase:label {
     8        bd:serviceParam wikibase:language "en"
     9     }
    10 }
    
Try it!

Canadian subjects with no English article in Wikipedia

#added before 2019-02

SELECT ?item ?itemLabel ?cnt WHERE {
{
  SELECT ?item (COUNT(?sitelink) AS ?cnt) WHERE { 
  ?item wdt:P27|wdt:P205|wdt:P17 wd:Q16 . #Canadian subjects.
  minus {?item wdt:P106 wd:Q488111 .} #Minus occupations that would be inappropriate in most situations.
  minus {?item wdt:P106 wd:Q3286043 .}
  minus {?item wdt:P106 wd:Q4610556 .}  
  ?sitelink schema:about ?item .
  FILTER NOT EXISTS {
    ?article schema:about ?item .
    ?article schema:isPartOf <https://en.wikipedia.org/> . #Targeting Wikipedia language where subjects has no article.
  }
  } GROUP BY ?item ORDER BY DESC (?cnt) LIMIT 1000 #Sorted by amount of articles in other languages. Result limited to 1000 lines to not have a timeout error.
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,fr,es,de" }  #Service to resolve labels in (fallback) languages: automatic user language, English, French, Spanish, German.
} ORDER BY DESC (?cnt)

Try it!

Countries that have a Featured Article on Russian Wikipedia

SELECT ?sitelink ?itemLabel WHERE {
  ?item wdt:P31 wd:Q6256.
  ?sitelink schema:isPartOf <https://ru.wikipedia.org/>;
     schema:about ?item;
     wikibase:badge wd:Q17437796 . # Sitelink is badged as a Featured Article
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" } .
} ORDER BY ?itemLabel

Try it!

Numbers of sitelinks for items with Art UK artist ID (P1367) for each language

SELECT ?lang (COUNT(DISTINCT ?article) AS ?count) WHERE {
  ?article schema:about/wdt:P1367 ?yp_id .  # find articles about things with a BBC 'Your paintings' artist identifier
  FILTER (SUBSTR(str(?article), 11, 15) = ".wikipedia.org/") .
  ?article schema:inLanguage ?lang .
} GROUP BY ?lang
ORDER BY DESC (?count)

Try it!

Titles of articles about Ukrainian villages on Romanian Wikipedia

#Show titles of articles about Ukrainian villages on Romanian Wikipedia, plus English and Ukrainian labels in Wikidata items
#added in 2017-05
SELECT DISTINCT ?item ?LabelEN ?LabelUK ?page_titleRO WHERE {
  ?item wdt:P31 wd:Q532 .  
  ?item wdt:P17 wd:Q212 .
  ?article schema:about ?item ; schema:isPartOf <https://ro.wikipedia.org/> ;  schema:name ?page_titleRO .
  ?item rdfs:label ?LabelEN filter (lang(?LabelEN) = "en") .
  ?item rdfs:label ?LabelUK filter (lang(?LabelUK) = "uk") .
}
LIMIT 300

Try it!

Wikisource pages for authors of scientific articles

#Wikisource pages for authors of scientific articles, ordered by Wikisource language
#added in 2017-09
SELECT DISTINCT ?item ?wikisourceSitelink ?wikisourceLanguage WHERE {
  ?wikisourceSitelink schema:isPartOf [ wikibase:wikiGroup "wikisource" ];
                      schema:inLanguage ?wikisourceLanguage;
                      schema:about ?item.
  ?paper wdt:P31 wd:Q13442814;
         wdt:P50 ?item.
}
ORDER BY ?wikisourceLanguage
LIMIT 300

Try it!

Items with a GTAA id and their articles on the Dutch and English Wikipedia

select ?item ?itemLabel ?gtaa ?_articleEN ?_articleNL where {
  ?item wdt:P1741 ?gtaa. # GTAA id
  OPTIONAL {
    ?_articleEN schema:about ?item.
    ?_articleNL schema:about ?item.
    ?_articleEN schema:isPartOf <https://en.wikipedia.org/>.
    ?_articleNL schema:isPartOf <https://nl.wikipedia.org/>.
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,nl". }
}

Try it!

People deceased in 2018 ordered by the number of sitelinks

select ?person ?personLabel ?died ?sitelinks where {
  ?person wdt:P31 wd:Q5;
          wdt:P570 ?died.
  filter (?died >= "2018-01-01T00:00:00Z"^^xsd:dateTime && ?died < "2019-01-01T00:00:00Z"^^xsd:dateTime)
  ?person wikibase:sitelinks ?sitelinks.
  service wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}  order by desc(?sitelinks) limit 100

Try it!

Entertainment

Rock bands that start with "M"

SELECT DISTINCT ?band ?bandLabel
WHERE
{
	?band  wdt:P31 wd:Q5741069 .
        ?band rdfs:label ?bandLabel .
	FILTER(STRSTARTS(?bandLabel, 'M')) .
}

Try it!

Winner of the Academy Awards by Award and Time

SELECT DISTINCT ?item ?itemLabel ?awardLabel ?time
{
    ?item wdt:P106/wdt:P279* wd:Q3455803 ; # Items with the Occupation(P106) of Director(Q3455803) or a subclass(P279)
          p:P166 ?awardStat .              # ... with an awarded(P166) statement
    ?awardStat pq:P805 ?award ;            # Get the award (which is "subject of" XXth Academy Awards)
               ps:P166 wd:Q103360 .        # ... that has the value Academy Award for Best Director(Q103360)
    ?award wdt:P585 ?time .                # the "point of time" of the Academy Award
    SERVICE wikibase:label {               # ... include the labels
        bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en"
    }
}
ORDER BY DESC(?time)

Try it!

Academy award data

#added before 2016-10
SELECT ?human ?humanLabel ?awardEditionLabel ?awardLabel ?awardWork ?awardWorkLabel ?director ?directorLabel ?time
WHERE
{
	{
		SELECT (SAMPLE(?human) AS ?human) ?award ?awardWork (SAMPLE(?director) AS ?director) (SAMPLE(?awardEdition) AS ?awardEdition) (SAMPLE(?time) AS ?time) WHERE {
			?award wdt:P31 wd:Q19020 .			# All items that are instance of(P31) of Academy awards (Q19020)
			{
				?human p:P166 ?awardStat .              # Humans with an awarded(P166) statement
				?awardStat ps:P166 ?award .     	 # ... that has any of the values of ?award
				?awardStat pq:P805 ?awardEdition . # Get the award edition (which is "subject of" XXth Academy Awards)
				?awardStat pq:P1686 ?awardWork . # The work they have been awarded for
				?human wdt:P31 wd:Q5 . 				# Humans
			} UNION {
				?awardWork wdt:P31 wd:Q11424 . # Films
				?awardWork p:P166 ?awardStat . # ... with an awarded(P166) statement
				?awardStat ps:P166 ?award .     	 # ... that has any of the values of ?award
				?awardStat pq:P805 ?awardEdition . # Get the award edition (which is "subject of" XXth Academy Awards)
			}
			OPTIONAL {
				?awardEdition wdt:P585 ?time . # the "point of time" of the Academy Award
				?awardWork wdt:P57 ?director .
			}
		}
		GROUP BY ?awardWork ?award # We only want every movie once for a category (a 'random' person is selected)
	}

	SERVICE wikibase:label {            # ... include the labels
		bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
	}
}
ORDER BY DESC(?time)

Try it!

People that received both Academy Award and Nobel Prize

The following query uses these:

  • Properties: award received (P166)  , instance of (P31)  
    1 SELECT DISTINCT ?person ?personLabel WHERE {
    2   ?person wdt:P166/wdt:P31? wd:Q7191 .
    3   ?person wdt:P166/wdt:P31? wd:Q19020 .
    4   SERVICE wikibase:label {
    5     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
    6   }
    7 }
    
Try it!

Number of handed out academy awards per award type

#added before 2016-10

SELECT ?awardCount ?award ?awardLabel WHERE {
	{
		SELECT (COUNT(?award) AS ?awardCount) ?award
		WHERE
		{
			{
				SELECT (SAMPLE(?human) AS ?human) ?award ?awardWork (SAMPLE(?director) AS ?director) (SAMPLE(?awardEdition) AS ?awardEdition) (SAMPLE(?time) AS ?time) WHERE {
					?award wdt:P31 wd:Q19020 .			# All items that are instance of(P31) of Academy awards (Q19020)
					{
						?human p:P166 ?awardStat .              # Humans with an awarded(P166) statement
						?awardStat ps:P166 ?award .     	 # ... that has any of the values of ?award
						?awardStat pq:P805 ?awardEdition . # Get the award edition (which is "subject of" XXth Academy Awards)
						?awardStat pq:P1686 ?awardWork . # The work they have been awarded for
						?human wdt:P31 wd:Q5 . 				# Humans
					} UNION {
						?awardWork wdt:P31 wd:Q11424 . # Films
						?awardWork p:P166 ?awardStat . # ... with an awarded(P166) statement
						?awardStat ps:P166 ?award .     	 # ... that has any of the values of ?award
						?awardStat pq:P805 ?awardEdition . # Get the award edition (which is "subject of" XXth Academy Awards)
					}
					OPTIONAL {
						?awardEdition wdt:P585 ?time . # the "point of time" of the Academy Award
						?awardWork wdt:P57 ?director .
					}
				}
				GROUP BY ?awardWork ?award # We only want every movie once for a category (a 'random' person is selected)
			}
		} GROUP BY ?award
		ORDER BY ASC(?awardCount)
	}
	SERVICE wikibase:label {            # ... include the labels
		bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
	}
}

Try it!

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

SELECT ?director ?director_label ?films ?sitelinks ((?films * ?sitelinks) as ?rank)
WHERE {
  {SELECT ?director (count(distinct ?film) as ?films) (count(distinct ?sitelink) as ?sitelinks)
     WHERE { 
       ?director wdt:P106 wd:Q2526255 .  				# has "film director" as occupation
	   ?film wdt:P57 ?director . 	 					# get all films directed by the director
       ?sitelink schema:about ?director .				# get all the sitelinks about the director
       } GROUP BY ?director }
SERVICE wikibase:label { 
  bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".  # Get label if it exists
?director rdfs:label ?director_label } 	
} ORDER BY DESC(?rank)
LIMIT 100

Try it!

The Simpsons television series episodes list by season

SELECT ?show ?showLabel ?seasonNumber ?episode ?episodeLabel
WHERE {
	BIND(wd:Q886 as ?show) .
	?season wdt:P361 ?show .
	?episode wdt:P361 ?season .
	?season p:P179 [
	        pq:P1545 ?seasonNumber] .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
} ORDER BY xsd:integer(?seasonNumber)

Try it!

Pokemon!

#updated 2019-01-21

# Gotta catch 'em all
SELECT DISTINCT ?pokemon ?pokemonLabel ?pokedexNumber
WHERE
{
    ?pokemon wdt:P31/wdt:P279* wd:Q3966183 .
    ?pokemon p:P1685 ?statement.
    ?statement ps:P1685 ?pokedexNumber;
              pq:P972 wd:Q20005020.
    FILTER ( !isBLANK(?pokedexNumber) ) .
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
ORDER BY (?pokedexNumber)

Try it!

Law & Order episodes

# All Law & Order episodes on Wikidata.
# According to enwp, “[a] total of 456 original episodes… aired before cancellation” (https://en.wikipedia.org/wiki/List_of_Law_%26_Order_episodes).
# As of this writing, the query returns 451 results, so some episodes are missing (either without item or lacking the necessary statements to match this query).

SELECT (SAMPLE(?seasonNumber) AS ?seasonNumber) (SAMPLE(?episodeNumber) AS ?episodeNumber) (SAMPLE(?title) AS ?title) (MIN(?pubDate) AS ?pubDate) ?episode
{
  # All episodes should be instance of episode with series Law & Order.
  ?episode wdt:P31 wd:Q21191270;
           wdt:P179 wd:Q321423.
  # Many of them also have the season as series, so we can get episode and season number from qualifiers there.
  OPTIONAL {
    ?episode p:P179 [
      # the season also has series Law & Order
      ps:P179/p:P179 [
        ps:P179 wd:Q321423;
                pq:P1545 ?seasonNumber
      ] ;
      pq:P1545 ?episodeNumber
    ]
  }
  OPTIONAL { ?episode wdt:P1476 ?title. }
  OPTIONAL { ?episode wdt:P577 ?pubDate. }
}
GROUP BY ?episode # make sure we return each episode only once – a few have multiple publication dates, for example
ORDER BY IF(BOUND(?seasonNumber), xsd:integer(?seasonNumber), 1000) xsd:integer(?episodeNumber) ?title

Try it!

Main subjects of West Wing episodes

SELECT DISTINCT ?episode ?ordinal ?episodeLabel ?subject ?subjectLabel
WHERE {
  ?episode wdt:P31/wdt:P279* wd:Q1983062;
           p:P179 ?statement.
  OPTIONAL{ ?episode wdt:P921 ?subject }
  ?statement ps:P179 wd:Q3577037;
             pq:P1545 ?ordinal
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY xsd:integer(?ordinal)

Try it!

Movies with Bud Spencer

SELECT ?item ?itemLabel (MIN(?date) AS ?firstReleased) ?_image
WHERE {
  ?item wdt:P161 wd:Q221074;
        wdt:P577 ?date
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P18 ?_image. }
} GROUP BY ?item ?itemLabel ?_image
ORDER BY (?date)

Try it!

Fictional subjects of the Marvel Universe

SELECT ?char ?charName (GROUP_CONCAT(DISTINCT ?typeLabel;separator=", ") AS ?types) (GROUP_CONCAT(DISTINCT ?universeLabel;separator=", ") AS ?universes)
WHERE {
	?char wdt:P1080 wd:Q931597;
          wdt:P31 ?type ;
          wdt:P1080 ?universe .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
                         ?char rdfs:label ?charName .
                         ?universe rdfs:label ?universeLabel .
                         ?type rdfs:label ?typeLabel .}
} GROUP BY ?char ?charName

Try it!

Contemporary Indian actresses

SELECT ?item ?itemLabel ?itemDescription (SAMPLE(?img) AS ?image) (SAMPLE(?dob) AS ?dob) ?sl
WHERE {
	?item wdt:P106 wd:Q33999 ;
          wdt:P27 wd:Q668 ;
          wdt:P21 wd:Q6581072 .
	MINUS { ?item wdt:P570 [] }
	OPTIONAL { ?item wdt:P18 ?img }
	OPTIONAL { ?item wdt:P569 ?dob } 
	OPTIONAL { ?item wikibase:sitelinks ?sl } 
  	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en"}
} GROUP BY ?item ?itemLabel ?itemDescription ?sl
ORDER BY DESC(?sl)

Try it!

Articles on Punjabi (Gurmukhi) Wikipedia about Pakistani actresses

#added 2017-03-25 (46 results)
SELECT ?sitelink
WHERE
{
	# gender = female
  	?item wdt:P21 wd:Q6581072 .

  	# country = Pakistan (Q25)
  	{ ?item wdt:P27 wd:Q843 }

        # occupation = actress (Q33999)
  	{ ?item wdt:P106 wd:Q33999 }
 
	# look for articles (sitelinks) in Punjabi ("pa")
  	{ ?sitelink schema:about ?item . ?sitelink schema:inLanguage "pa" }

	# humans only
  	?item wdt:P31 wd:Q5 .
}
#Listeria can only handle up to 5000
LIMIT 5000

Try it!

All Dr. Who performers

The following query uses these:

  • Properties: instance of (P31)  , series ordinal (P1545)  , performer (P175)  
    1 #added 2017-07-16
    2 SELECT ?doctor ?doctorLabel ?ordinal ?performer ?performerLabel WHERE {
    3   ?doctor wdt:P31 wd:Q34358 .
    4   OPTIONAL { ?doctor wdt:P1545 ?ordinal }
    5   OPTIONAL { ?doctor wdt:P175 ?performer }
    6   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
    7 } ORDER BY ASC(xsd:integer(?ordinal) )
    
Try it!

Movies and their narrative location on a map

The following query uses these:

Features: Map (Q24515275)  

1 #defaultView:Map
2 SELECT ?movie ?movieLabel ?narrative_location ?narrative_locationLabel ?coordinates WHERE {
3    ?movie wdt:P840 ?narrative_location ;
4           wdt:P31 wd:Q11424 .
5    ?narrative_location wdt:P625 ?coordinates .
6   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
7 }
Try it!

Movies released in 2017

The following query uses these:

  • Properties: instance of (P31)  , publication date (P577)  
    1 SELECT DISTINCT ?item ?itemLabel WHERE {
    2   ?item wdt:P31 wd:Q11424.
    3   ?item wdt:P577 ?pubdate.
    4   FILTER((?pubdate >= "2017-01-01T00:00:00Z"^^xsd:dateTime) && (?pubdate <= "2017-12-31T00:00:00Z"^^xsd:dateTime))
    5   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    6 }
    
Try it!

Musicians or singers that have a genre containing 'rock'

SELECT DISTINCT ?human ?humanLabel
WHERE
{
    VALUES ?professions {wd:Q177220 wd:Q639669}
    ?human wdt:P31 wd:Q5 .
    ?human wdt:P106 ?professions .
    ?human wdt:P136 ?genre .
    ?human wikibase:statements ?statementcount .
    ?genre rdfs:label ?genreLabel .  
    FILTER CONTAINS(?genreLabel, "rock") .
    FILTER (?statementcount > 50 ) .
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?humanLabel
LIMIT 50

Try it!

Geography

Continents

Continents

#added before 2016-10

SELECT ?continent ?continentLabel
WHERE
{
  ?continent wdt:P31 wd:Q5107.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY xsd:integer(SUBSTR(STR(?continent),STRLEN("http://www.wikidata.org/entity/Q")+1))

Try it!

Some other continents

continent (P30)

#added before 2016-10

SELECT ?continentLabel
WHERE
{
  { # subquery for optimization so the label service doesn’t have to do as much work (228?ms vs 20731?ms)
    SELECT DISTINCT ?continent
    WHERE
    {
      [] wdt:P30 ?continent.
    }
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY xsd:integer(SUBSTR(STR(?continent),STRLEN("http://www.wikidata.org/entity/Q")+1))

Try it!

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

#added before 2016-10

#defaultView:Map
SELECT ?place ?placeLabel ?location WHERE {
  wd:Q933 wdt:P625 ?southPole.                         # coordinates of south pole
  ?place wdt:P30 wd:Q51;                               # continent: antarctica
         wdt:P625 ?location.
  FILTER(geof:distance(?location, ?southPole) > 3000). # over 3000?km away from south pole
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

Countries

List of present-day countries and capital(s)

#added before 2016-10
SELECT DISTINCT ?country ?countryLabel ?capital ?capitalLabel
WHERE
{
  ?country wdt:P31 wd:Q3624078 .
  #not a former country
  FILTER NOT EXISTS {?country wdt:P31 wd:Q3024240}
  #and no an ancient civilisation (needed to exclude ancient Egypt)
  FILTER NOT EXISTS {?country wdt:P31 wd:Q28171280}
  OPTIONAL { ?country wdt:P36 ?capital } .

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?countryLabel

Try it!

UN member states

SELECT DISTINCT ?state WHERE {
  ?state wdt:P31/wdt:P279* wd:Q3624078;
         p:P463 ?memberOfStatement.
  ?memberOfStatement a wikibase:BestRank;
                     ps:P463 wd:Q1065.
  MINUS { ?memberOfStatement pq:P582 ?endTime. }
  MINUS { ?state wdt:P576|wdt:P582 ?end. }
}

Try it!

Largest cities per country

#added before 2016-10

#Largest cities per country
SELECT DISTINCT ?city ?cityLabel ?population ?country ?countryLabel ?loc WHERE {
	{
		SELECT (MAX(?population) AS ?population) ?country WHERE {
			?city wdt:P31/wdt:P279* wd:Q515 .
			?city wdt:P1082 ?population .
			?city wdt:P17 ?country .
		}
		GROUP BY ?country
		ORDER BY DESC(?population)
	}
	?city wdt:P31/wdt:P279* wd:Q515 .
	?city wdt:P1082 ?population .
	?city wdt:P17 ?country .
	?city wdt:P625 ?loc .
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en" .
	}
}

Try it!

Wikidata people per million inhabitants for all EU countries

#added before 2016-10

#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 uncommenting the line as indicated below
SELECT
	?country ?countryLabel
	?wikiPersons
	?population
	(ROUND(?wikiPersons/?population*1000000) AS ?wikiPersonsPerM)
WHERE
{
	{ SELECT ?country (count(*) as ?wikiPersons) WHERE {
		{SELECT DISTINCT ?person ?country WHERE {
			wd:Q458 wdt:P150 ?country .   # European Union  contains administrative territorial entity
			# BIND( wd:Q30 AS ?country ) # use instead of previous line to check individual countries
			?person wdt:P31 wd:Q5 .
			?person wdt:P27 ?country .
			FILTER NOT EXISTS{ ?person wdt:P570 ?date } # only count living people
		} }
	} GROUP BY ?country  }
	?country wdt:P1082 ?population
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY DESC(?wikiPersonsPerM)

Try it!

Papers about wikidata

#added before 2016-10

#papers about Wikidata
SELECT ?item ?itemLabel
WHERE
{
  ?item (wdt:P31/wdt:P279*) wd:Q191067.
  ?item wdt:P921 wd:Q2013.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 100

Try it!

Countries sorted by population

# defaultView:BubbleChart
SELECT DISTINCT ?countryLabel ?population
{
  ?country wdt:P31 wd:Q6256 ;
           wdt:P1082 ?population .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?population ?countryLabel
ORDER BY DESC(?population)

Try it!

Country populations together with total city populations

Lists for each country the population and the total of the populations of all cities of this country. If data were complete and populations were measured at the same time for each country and the respective cities then the ratio would be 1.

SELECT ?country ?countryLabel ?population ?totalCityPopulation (?population / ?totalCityPopulation AS ?ratio) {
  ?country wdt:P1082 ?population .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
  {
    SELECT ?country (SUM(?cityPopulation) AS ?totalCityPopulation) WHERE {
      ?city wdt:P31 wd:Q515 .
      ?city wdt:P17 ?country .
      ?city wdt:P1082 ?cityPopulation .
    } GROUP BY ?country
  }
} ORDER BY ?ratio

Try it!

Names of African countries in all their official languages and English

The following query uses these:

  • Properties: continent (P30)  , official language (P37)  , instance of (P31)  , Wikimedia language code (P424)  
     1 SELECT DISTINCT ?item ?itemLabel_ol ?official_language ?itemLabel_en WHERE {
     2   ?item wdt:P30 wd:Q15 ;
     3         wdt:P37 ?officiallanguage ;
     4         wdt:P31 wd:Q6256 .
     5   ?officiallanguage wdt:P424 ?langcode .
     6   ?item rdfs:label ?itemLabel_ol . FILTER(lang(?itemLabel_ol)=?langcode)
     7   ?item rdfs:label ?itemLabel_en . FILTER(lang(?itemLabel_en)='en')
     8   ?officiallanguage rdfs:label ?official_language . FILTER(lang(?official_language)='en')
     9 }
    10 ORDER BY ?item ?itemLabel_lol ?official_language
    
Try it!

Cities

Population of cities and towns in Denmark and their OSM relation id

# Population of cities and towns in Denmark and their OSM relation id
# This shows a simple OR using VALUES and a variable
SELECT ?city ?cityLabel ?population ?OSM_relation_ID WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  VALUES ?town_or_city {
    wd:Q3957
    wd:Q515
  }
  ?city (wdt:P31/(wdt:P279*)) ?town_or_city;
    wdt:P17 wd:Q35.
  OPTIONAL { ?city wdt:P1082 ?population. }
  OPTIONAL { ?city wdt:P402 ?OSM_relation_ID. }
}
LIMIT 100

Try it!

Former capitals

#added before 2016-10

#defaultView:Map
SELECT DISTINCT ?country ?countryLabel ?capital ?capitalLabel ?coordinates ?ended
WHERE
{
  ?country p:P36 ?stat.
  ?stat ps:P36 ?capital.
  ?capital wdt:P625 ?coordinates.
  OPTIONAL {
    ?country wdt:P582|wdt:P576 ?ended.
  }
  OPTIONAL {
    ?capital wdt:P582|wdt:P576 ?ended.
  }
  OPTIONAL {
    ?stat pq:P582 ?ended.
  }
  FILTER(BOUND(?ended)).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

Largest cities of the world

#added before 2016-10
 #defaultView:BubbleChart
SELECT DISTINCT ?cityLabel ?population ?gps
WHERE
{
  ?city wdt:P31/wdt:P279* wd:Q515 .
  ?city wdt:P1082 ?population .
  ?city wdt:P625 ?gps .
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
  }
}
ORDER BY DESC(?population) LIMIT 100

Try it!

Cities as big as Eindhoven give or take 1000

#added before 2016-10

#defaultView:Map
SELECT DISTINCT ?city ?cityLabel ?location ?populatie2 WHERE {
  wd:Q9832 wdt:P1082 ?populatie .
  ?city wdt:P1082 ?populatie2 ;
        wdt:P625 ?location .
  FILTER (abs(?populatie - ?populatie2) < 1000)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],nl" }
}

Try it!

Where in the world is Antwerp

The following query uses these:

Features: Map (Q24515275)  

 1 #added before 2016-10
 2 
 3 #defaultView:Map
 4 SELECT DISTINCT ?settlement ?name ?coor
 5 WHERE
 6 {
 7   
 8    ?subclass_settlement wdt:P279+ wd:Q486972 .
 9    ?settlement wdt:P31 ?subclass_settlement ;
10                wdt:P625 ?coor ;
11                 rdfs:label ?name .
12    FILTER regex(?name, "Antwerp", "i")
13 
14 }
Try it!

Destinations from Antwerp International airport

The following query uses these:

Features: Map (Q24515275)  

 1 #added before 2016-10
 2 
 3 #defaultView:Map
 4 SELECT ?connectsairport ?connectsairportLabel ?place_served ?place_servedLabel ?coor
 5 WHERE
 6 {
 7   VALUES ?airport { wd:Q17480 } # Antwerp international airport  wd:Q17480
 8   ?airport wdt:P81 ?connectsairport ;
 9            wdt:P625 ?base_airport_coor .
10   ?connectsairport wdt:P931 ?place_served ;
11                    wdt:P625 ?coor .
12  
13   SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
14 }
Try it!

Cities connected by the European route E40

The following query uses these:

Features: Map (Q24515275)  

 1 #added before 2016-10
 2 
 3 #defaultView:Map
 4 SELECT ?city ?cityLabel ?coordinates
 5 WHERE
 6 {
 7    VALUES ?highway {wd:Q327162 }
 8    ?highway wdt:P2789 ?city .
 9     ?city wdt:P625 ?coordinates .
10    SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
11 }
Try it!

Cities connected by the Trans-Mongolian and Trans-Siberian Railway

The following query uses these:

Features: Map (Q24515275)  

 1 #added before 2016-10
 2 
 3 #defaultView:Map
 4 SELECT ?city ?cityLabel ?coordinates
 5 WHERE
 6 {
 7    VALUES ?highway { wd:Q559037 wd:Q58767 }
 8    ?highway wdt:P2789 ?city .
 9     ?city wdt:P625 ?coordinates .
10    SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
11 }
Try it!

Cities connected to Paramaribo (Suriname) by main roads

The following query uses these:

Features: Map (Q24515275)  

 1 #added before 2016-10
 2 
 3 #defaultView:Map
 4 SELECT DISTINCT ?connection ?connectionLabel ?connectedWith ?connectedWithLabel ?coor
 5 WHERE
 6 {
 7   VALUES ?city {wd:Q3001} # wd:Q3001 = Paramaribo}
 8   ?connection wdt:P2789+ ?city ;
 9               wdt:P2789+ ?connectedWith .
10   ?connectedWith wdt:P625 ?coor .
11   SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
12   }
Try it!

Names of 100 cities with a population larger than 1000000 in the native languages of their countries

The following query uses these:

  • Properties: population (P1082)  , instance of (P31)  , country (P17)  , official language (P37)  , Wikimedia language code (P424)  
     1 #added before 2016-10
     2 
     3 # Show the names of 100 cities with a population larger than 1000000 in the native languages of their countries
     4 SELECT ?city ?cityLabel ?country ?countryLabel ?lang ?langLabel ?langCode ?population
     5 WHERE
     6 {
     7   ?city wdt:P1082 ?population .
     8  
     9   FILTER(?population>1000000)
    10  
    11   ?city wdt:P31 wd:Q515;
    12         wdt:P17 ?country;
    13         rdfs:label ?cityLabel .
    14   ?country wdt:P37 ?lang;
    15            rdfs:label ?countryLabel .
    16   ?lang wdt:P424 ?langCode;
    17         rdfs:label ?langLabel .
    18  
    19   FILTER(lang(?cityLabel)=?langCode)
    20   FILTER(lang(?countryLabel)=?langCode)
    21   FILTER(lang(?langLabel)=?langCode)
    22 } LIMIT 100
    
Try it!

Distances between any two cities or municipalities in an area

grouped by dist range, color-coded

The following query uses these:

  • Properties: instance of (P31)  , subclass of (P279)  , located in the administrative territorial entity (P131)  , coordinate location (P625)  
     1 #defaultView:BarChart
     2 PREFIX var_muntype: <http://www.wikidata.org/entity/Q15284>
     3 PREFIX var_area: <http://www.wikidata.org/entity/Q6308>
     4 SELECT ?from ?to ?distGrp WHERE {
     5   {
     6     SELECT ?from ?to ?distNum ?mun ?mun2 WHERE {
     7       { SELECT ?mun (SAMPLE(?loc) AS ?loc)
     8         WHERE { ?mun wdt:P31/wdt:P279* var_muntype:;
     9                      wdt:P131 var_area:;
    10                      wdt:P625 ?loc. }
    11         GROUP BY ?mun
    12       }
    13       OPTIONAL {
    14         { SELECT (?mun AS ?mun2) (SAMPLE(?loc) AS ?loc2)
    15           WHERE { ?mun wdt:P31/wdt:P279* var_muntype:;
    16                        wdt:P131 var_area:;
    17                        wdt:P625 ?loc. }
    18           GROUP BY ?mun
    19         }
    20       }
    21       BIND(geof:distance(?loc, ?loc2) AS ?distNum).
    22 
    23       SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
    24         ?mun rdfs:label ?from.
    25         ?mun2 rdfs:label ?to.
    26       }
    27     }
    28   }
    29   FILTER(CONCAT(?from,STR(?mun)) <= CONCAT(?to,STR(?mun2))).
    30   #BIND(IF(STR(?from) < STR(?to),CONCAT(?from," <--> ",?to),
    31   #  CONCAT(?to," <--> ",?from)) AS ?distLabel).
    32 
    33   BIND(COALESCE(
    34     IF(?distNum >= 40, "40 - .. km", 1/0),
    35     IF(?distNum >= 30, "30 - 40 km", 1/0),
    36     IF(?distNum >= 20, "20 - 30 km", 1/0),
    37     IF(?distNum >= 10, "10 - 20 km", 1/0),
    38     IF(?distNum >= 5, "05 - 10 km", 1/0),
    39     IF(?distNum >= 1, "01 - 05 km", "00 - 01 km")) AS ?distGrp).
    40 }
    41 ORDER BY ?from ?distGrp
    
Try it!
grouped per municipality on x-axis, alphabetically

The following query uses these:

  • Properties: instance of (P31)  , subclass of (P279)  , located in the administrative territorial entity (P131)  , coordinate location (P625)  
     1 #defaultView:ScatterChart
     2 PREFIX var_muntype: <http://www.wikidata.org/entity/Q15284>
     3 PREFIX var_area: <http://www.wikidata.org/entity/Q6308>
     4 SELECT ?from (?distGrp1 AS ?kilometers) ?to WHERE {
     5   { SELECT ?mun (SAMPLE(?loc) AS ?loc)
     6     WHERE { ?mun wdt:P31/wdt:P279* var_muntype:;
     7                  wdt:P131 var_area:;
     8                  wdt:P625 ?loc. }
     9     GROUP BY ?mun
    10   }
    11   OPTIONAL {
    12     { SELECT (?mun AS ?mun2) (SAMPLE(?loc) AS ?loc2)
    13       WHERE { ?mun wdt:P31/wdt:P279* var_muntype:;
    14                    wdt:P131 var_area:;
    15                    wdt:P625 ?loc. }
    16       GROUP BY ?mun
    17     }
    18   }
    19   BIND(geof:distance(?loc, ?loc2) AS ?distNum).
    20   BIND(STR(ROUND(?distNum)) AS ?distGrp0).
    21   BIND(CONCAT(SUBSTR("000",STRLEN(?distGrp0)+1),?distGrp0,".",STR(ROUND((?distNum-FLOOR(?distNum))*10))," km") AS ?distGrp1).
    22 
    23   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
    24     ?mun rdfs:label ?from.
    25     ?mun2 rdfs:label ?to.
    26   }
    27 }
    28 ORDER BY ?from ?kilometers
    
Try it!
grouped per municipality on x-axis, by sum of dist

The following query uses these:

  • Properties: instance of (P31)  , subclass of (P279)  , located in the administrative territorial entity (P131)  , coordinate location (P625)  
     1 #defaultView:ScatterChart
     2 PREFIX var_muntype: <http://www.wikidata.org/entity/Q15284>
     3 PREFIX var_area: <http://www.wikidata.org/entity/Q6308>
     4 SELECT ?from (?distNum AS ?kilometers) ?to WHERE {
     5   { SELECT ?mun (SAMPLE(?loc) AS ?loc)
     6     WHERE { ?mun wdt:P31/wdt:P279* var_muntype:;
     7                  wdt:P131 var_area:;
     8                  wdt:P625 ?loc. }
     9     GROUP BY ?mun
    10   }
    11   OPTIONAL {
    12     { SELECT (?mun AS ?mun2) (SAMPLE(?loc) AS ?loc2)
    13       WHERE { ?mun wdt:P31/wdt:P279* var_muntype:;
    14                    wdt:P131 var_area:;
    15                    wdt:P625 ?loc. }
    16       GROUP BY ?mun
    17     }
    18   }
    19   BIND(geof:distance(?loc, ?loc2) AS ?distNum).
    20 
    21   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
    22     ?mun rdfs:label ?from.
    23     ?mun2 rdfs:label ?to.
    24   }
    25 }
    26 ORDER BY ?from ?kilometers
    
Try it!
grouped per municipality on x-axis, animated per municipality on x-axis

The following query uses these:

  • Properties: instance of (P31)  , subclass of (P279)  , located in the administrative territorial entity (P131)  , coordinate location (P625)  
     1 #defaultView:ScatterChart
     2 PREFIX var_muntype: <http://www.wikidata.org/entity/Q15284>
     3 PREFIX var_area: <http://www.wikidata.org/entity/Q6308>
     4 SELECT ?from (?distNum AS ?kilometers) ?to (?from AS ?animation) WHERE {
     5   { SELECT ?mun (SAMPLE(?loc) AS ?loc)
     6     WHERE { ?mun wdt:P31/wdt:P279* var_muntype:;
     7                  wdt:P131 var_area:;
     8                  wdt:P625 ?loc. }
     9     GROUP BY ?mun
    10   }
    11   OPTIONAL {
    12     { SELECT (?mun AS ?mun2) (SAMPLE(?loc) AS ?loc2)
    13       WHERE { ?mun wdt:P31/wdt:P279* var_muntype:;
    14                    wdt:P131 var_area:;
    15                    wdt:P625 ?loc. }
    16       GROUP BY ?mun
    17     }
    18   }
    19   BIND(geof:distance(?loc, ?loc2) AS ?distNum).
    20 
    21   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
    22     ?mun rdfs:label ?from.
    23     ?mun2 rdfs:label ?to.
    24   }
    25 }
    26 ORDER BY ?from ?kilometers
    
Try it!
grouped per municipality on x-axis, animated per municipality on z-axis

The following query uses these:

  • Properties: instance of (P31)  , subclass of (P279)  , located in the administrative territorial entity (P131)  , coordinate location (P625)  
     1 #defaultView:ScatterChart
     2 PREFIX var_muntype: <http://www.wikidata.org/entity/Q15284>
     3 PREFIX var_area: <http://www.wikidata.org/entity/Q6308>
     4 SELECT ?from (?distNum AS ?kilometers) ?to (?to AS ?animation) WHERE {
     5   { SELECT ?mun (SAMPLE(?loc) AS ?loc)
     6     WHERE { ?mun wdt:P31/wdt:P279* var_muntype:;
     7                  wdt:P131 var_area:;
     8                  wdt:P625 ?loc. }
     9     GROUP BY ?mun
    10   }
    11   OPTIONAL {
    12     { SELECT (?mun AS ?mun2) (SAMPLE(?loc) AS ?loc2)
    13       WHERE { ?mun wdt:P31/wdt:P279* var_muntype:;
    14                    wdt:P131 var_area:;
    15                    wdt:P625 ?loc. }
    16       GROUP BY ?mun
    17     }
    18   }
    19   BIND(geof:distance(?loc, ?loc2) AS ?distNum).
    20 
    21   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
    22     ?mun rdfs:label ?from.
    23     ?mun2 rdfs:label ?to.
    24   }
    25 }
    26 ORDER BY ?from ?kilometers
    
Try it!
grouped per municipality on x-axis, animated by fixed dist range groups

The following query uses these:

  • Properties: instance of (P31)  , subclass of (P279)  , located in the administrative territorial entity (P131)  , coordinate location (P625)  
     1 #defaultView:ScatterChart
     2 PREFIX var_muntype: <http://www.wikidata.org/entity/Q15284>
     3 PREFIX var_area: <http://www.wikidata.org/entity/Q6308>
     4 SELECT ?from (?distNum AS ?kilometers) ?to (?distGrp AS ?animation) WHERE {
     5   { SELECT ?mun (SAMPLE(?loc) AS ?loc)
     6     WHERE { ?mun wdt:P31/wdt:P279* var_muntype:;
     7                  wdt:P131 var_area:;
     8                  wdt:P625 ?loc. }
     9     GROUP BY ?mun
    10   }
    11   OPTIONAL {
    12     { SELECT (?mun AS ?mun2) (SAMPLE(?loc) AS ?loc2)
    13       WHERE { ?mun wdt:P31/wdt:P279* var_muntype:;
    14                    wdt:P131 var_area:;
    15                    wdt:P625 ?loc. }
    16       GROUP BY ?mun
    17     }
    18   }
    19   #FILTER (STR(?mun) <= STR(?mun2)).
    20   BIND(geof:distance(?loc, ?loc2) AS ?distNum).
    21   BIND(COALESCE(
    22     IF(?distNum >= 40, "40 km und mehr", 1/0),
    23     IF(?distNum >= 30, "30 - 40 km", 1/0),
    24     IF(?distNum >= 20, "20 - 30 km", 1/0),
    25     IF(?distNum >= 10, "10 - 20 km", 1/0),
    26     IF(?distNum >= 5, "05 - 10 km", 1/0),
    27     IF(?distNum >= 1, "01 - 05 km", "00 - 01 km")) AS ?distGrp).
    28   
    29   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
    30     ?mun rdfs:label ?from.
    31     ?mun2 rdfs:label ?to.
    32   }
    33 }
    34 ORDER BY ?animation ?from ?kilometers
    
Try it!
grouped per municipality on x-axis, animated by ranked dist (farthest, 2nd farthest, ..)

The following query uses these:

  • Properties: instance of (P31)  , subclass of (P279)  , located in the administrative territorial entity (P131)  , coordinate location (P625)  
     1 #defaultView:ScatterChart
     2 PREFIX var_muntype: <http://www.wikidata.org/entity/Q15284>
     3 PREFIX var_area: <http://www.wikidata.org/entity/Q6308>
     4 SELECT ?from ?kilometers ?to ?rank_group
     5 WHERE {
     6   {
     7     SELECT (SAMPLE(?mun) AS ?mun) (SAMPLE(?mun2) AS ?mun2) (SAMPLE(?distNum) AS ?kilometers)
     8            (COUNT(*)-1 AS ?rg) (SUBSTR("00",1+STRLEN(STR(?rg))) AS ?rgpad)
     9            (IF(FLOOR((?rg-(100*FLOOR(?rg/100)))/10)=1,0,?rg-(10*FLOOR(?rg/10))) AS ?rgmod)
    10            (IF(?rgmod=1,"st",IF(?rgmod=2,"nd",IF(?rgmod=3,"rd","th"))) AS ?rgord)
    11            (CONCAT(?rgpad,STR(?rg),?rgord,"-most farthest places") AS ?rank_group)
    12     WHERE {
    13       { SELECT ?mun (SAMPLE(?loc) AS ?loc)
    14         WHERE { ?mun wdt:P31/wdt:P279* var_muntype:;
    15                      wdt:P131 var_area:;
    16                      wdt:P625 ?loc. }
    17         GROUP BY ?mun
    18       }
    19       OPTIONAL {
    20         { SELECT (?mun AS ?mun2) (SAMPLE(?loc) AS ?loc2)
    21           WHERE { ?mun wdt:P31/wdt:P279* var_muntype:;
    22                        wdt:P131 var_area:;
    23                        wdt:P625 ?loc. }
    24           GROUP BY ?mun
    25         }
    26       }
    27       OPTIONAL {
    28         { SELECT (?mun AS ?mun3) (SAMPLE(?loc) AS ?loc3)
    29           WHERE { ?mun wdt:P31/wdt:P279* var_muntype:;
    30                        wdt:P131 var_area:;
    31                        wdt:P625 ?loc. }
    32           GROUP BY ?mun
    33         }
    34       }
    35       BIND(geof:distance(?loc, ?loc2) AS ?distNum).
    36       BIND(geof:distance(?loc, ?loc3) AS ?d).
    37       FILTER(?distNum >= ?d).
    38     } GROUP BY ?mun ?mun2 ?distNum
    39   }
    40   
    41   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
    42     ?mun rdfs:label ?from.
    43     ?mun2 rdfs:label ?to.
    44   }
    45 }
    46 ORDER BY ?rank_group ?kilometers ?from
    
Try it!

Show all Dutch municipalities that share a border with Alphen aan den Rijn (Q213246), ignoring rank

select ?muni ?muniLabel where {
  ?muni p:P31 [ps:P31 wd:Q2039348];
        wdt:P47 wd:Q213246.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "nl". }
}

Try it!

Border cities of the world

The following query uses these:

Features: Map (Q24515275)  

 1 # To filter by country add FILTER (?country = wd:Qxx)
 2 #defaultView:Map
 3 # To show the cities of several countries use FILTER (?country IN (wd:Qxx, wd:Qyy))
 4 # To obtain cities that are part of a particular continent or territory ?country
 5 # should not be optional and add "?country wdt:P361 wd:Qxx ."
 6 
 7 SELECT ?border_city ?border_cityLabel ?countryLabel ?coords 
 8 WHERE {
 9   ?border_city wdt:P31 wd:Q902814.
10   OPTIONAL { ?border_city wdt:P17 ?country. }
11   OPTIONAL { ?border_city wdt:P625 ?coords. }
12   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". 
13                          ?border_city rdfs:label ?border_cityLabel.
14                          ?country  rdfs:label ?countryLabel.}
15 }
16 GROUP BY ?border_city ?border_cityLabel ?countryLabel ?coords
17 order by ?countryLabel ?border_cityLabel
Try it!

Rivers

Longest rivers

The following query uses these:

Features: BubbleChart (Q24515280)  

 1 #added before 2016-10
 2 
 3 #defaultView:BubbleChart
 4 SELECT ?item ?itemLabel ?length ?pic ?location
 5 WHERE
 6 {
 7   ?item wdt:P31/wdt:P279* wd:Q4022 .
 8   ?item wdt:P2043 ?length .
 9   ?item wdt:P18 ?pic .
10   ?item wdt:P625 ?location
11   SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
12 } ORDER BY DESC(?length) ?itemLabel
13 LIMIT 50
Try it!

Longest river of each continent

The following query uses these:

  • Properties: instance of (P31)  , subclass of (P279)  , length (P2043)  , continent (P30)  
     1 #added before 2016-10
     2 
     3 SELECT ?continent ?river ?continentLabel ?riverLabel
     4 WHERE
     5 {
     6   {
     7     SELECT ?continent (MAX(?length) AS ?length)
     8     WHERE
     9     {
    10       ?river wdt:P31/wdt:P279* wd:Q355304;
    11              wdt:P2043 ?length;
    12              wdt:P30 ?continent.
    13     }
    14     GROUP BY ?continent
    15   }
    16   ?river wdt:P31/wdt:P279* wd:Q355304;
    17          wdt:P2043 ?length;
    18          wdt:P30 ?continent.
    19   SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    20 }
    21 ORDER BY ?continentLabel
    
Try it!

Rivers in Antarctica

#added before 2016-10

SELECT ?river ?riverLabel ?location
WHERE
{
  ?river wdt:P31/wdt:P279* wd:Q355304; # watercourse; includes a few creeks – use wd:Q4022 for rivers only
         wdt:P30 wd:Q51.
  OPTIONAL { ?river wdt:P625 ?location. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

Body of water with the most watercourses ending in it

#added before 2016-10

# Bodies of water that most watercourses end in (transitive).
# For example, over 4000 watercourses eventually flow into the Ob,
# and since the Ob flows into the Kara Sea, the Kara Sea has over 4000 results as well.
SELECT ?mouth (COUNT(?watercourse) AS ?count)
WHERE
{
  ?watercourse wdt:P403+ ?mouth.
}
GROUP BY ?mouth
ORDER BY DESC(?count)
LIMIT 10

Try it!

Bridges over rivers in former government district of Leipzig

The following query uses these:

Features: Map (Q24515275)  

 1 #defaultView:Map
 2 SELECT (SAMPLE(?bridge) AS ?bridge) (SAMPLE(?bridgeLabel) AS ?bridgeLabel)
 3        (SAMPLE(?watercourse) AS ?watercourse) (SAMPLE(?watercourseLabel) AS ?watercourseLabel)
 4        (SAMPLE(?loc) AS ?loc) (SAMPLE(?pic) AS ?pic)
 5        (CONCAT(SAMPLE(?sKey),": ",STR(YEAR(SAMPLE(?s)))) AS ?start)
 6        (CONCAT(SAMPLE(?eKey),": ",STR(YEAR(SAMPLE(?e)))) AS ?end)
 7        (SAMPLE(?article) AS ?article) (IF(BOUND(?article),CONCAT(?bridgeLabel," in Wikipedia"),1/0) AS ?articleLabel)
 8 WHERE {
 9   {
10     SELECT ?bridge ?watercourse WHERE {
11       ?bridge wdt:P31/wdt:P279* wd:Q12280; wdt:P177 ?watercourse.
12       ?watercourse wdt:P31/wdt:P279* wd:Q355304.
13       # the following actually yields a perf penalty atm
14       #?bridge wdt:P17 wd:Q183.
15       #OPTIONAL { ?bridge wdt:P17 ?country. }. FILTER(!BOUND(?country) || ?country = wd:Q183).
16     }
17   }
18 
19   # wd:Q1202, wd:Q183 work as well atm and take progressively more time to complete
20   ?bridge (p:P131|ps:P131)+ wd:Q24186.
21 
22   OPTIONAL { ?bridge wdt:P625 ?loc. }.
23   OPTIONAL { ?bridge wdt:P18 ?pic. }.
24   OPTIONAL { ?bridge wdt:P571 ?s. }.
25   OPTIONAL { ?bridge wdt:P576 ?e. }.
26   
27   OPTIONAL {
28     ?article schema:about ?bridge.
29     FILTER (IF(EXISTS {?article schema:inLanguage "[AUTO_LANGUAGE]".},
30                SUBSTR(str(?article), 1, 25) = "https://[AUTO_LANGUAGE].wikipedia.org/",
31                IF(EXISTS {?article schema:inLanguage "en".},
32                   SUBSTR(str(?article), 1, 25) = "https://en.wikipedia.org/",
33                   SUBSTR(str(?article), 1, 25) = "https://de.wikipedia.org/"
34                )
35             )).
36   }
37 
38   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,de".
39     ?bridge rdfs:label ?bridgeLabel.
40     ?watercourse rdfs:label ?watercourseLabel.
41     wd:P571 rdfs:label ?sKey.
42     wd:P576 rdfs:label ?eKey.
43   }
44 }
45 GROUP BY ?bridge ?watercourse
Try it!

Mountains

Mountains, with coordinates, not located on Earth

SELECT DISTINCT ?item ?name ?coord ?lat ?lon ?globe
{
   ?item wdt:P31 wd:Q8502 ;
         p:P625 [
           psv:P625 [
             wikibase:geoLatitude ?lat ;
             wikibase:geoLongitude ?lon ;
             wikibase:geoGlobe ?globe ;
           ] ;
           ps:P625 ?coord
         ]
  FILTER ( ?globe != wd:Q2 )
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
    ?item rdfs:label ?name
   }
}
ORDER BY ASC (?name)

Try it!

Highest mountains in the universe

#added before 2016-10

#Mountains over 8000 elevation
SELECT ?subj ?label ?coord ?elev
WHERE
{
	?subj wdt:P2044 ?elev	filter(?elev > 8000) .
	?subj wdt:P625 ?coord .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en,zh" . ?subj rdfs:label ?label }
}

Try it!

Mountains over 8000 elevation

elevation above sea level (P2044)

#added before 2016-10

SELECT ?subj ?label ?coord ?elev
WHERE
{
	?subj wdt:P2044 ?elev	filter(?elev > 8000) .
	?subj wdt:P625 ?coord .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en,zh" . ?subj rdfs:label ?label }
}

Try it!

Italian mountains higher than 4000 m

#defaultView:ImageGrid
SELECT ?item ?itemLabel ?coord ?elev ?picture
{
  ?item p:P2044/psn:P2044/wikibase:quantityAmount ?elev ;  # normalized height
        wdt:P625 ?coord ;
        wdt:P17 wd:Q38 ;
        wdt:P18 ?picture
  FILTER(?elev > 4000)

  SERVICE wikibase:label { bd:serviceParam wikibase:language "it" }
}

Try it!

Metro stations in Paris

SELECT ?item ?itemLabel ?adjacent ?adjacentL ?coords
{
  ?item wdt:P31/wdt:P279* wd:Q928830 ;
        wdt:P81 wd:Q13224 ;
        wdt:P625 ?coords .
  OPTIONAL {
    ?item p:P197 [ ps:P197 ?adjacent ; pq:P5051 wd:Q585752;
                                       pq:P81 wd:Q13224] .
    ?adjacent rdfs:label ?adjacentL filter (lang(?adjacentL) = "en")
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
} ORDER BY ?itemLabel

Try it!

Map of Broadway venues

#added before 2016-10

#defaultView:Map
# Venues in Broadway
SELECT DISTINCT ?venue ?venueLabel ?coords {
  	?venue wdt:P1217 ?IDBDB .
    wd:Q235065 wdt:P625 ?broadWayLoc .

    SERVICE wikibase:around {
      ?venue wdt:P625 ?coords .
      bd:serviceParam wikibase:center ?broadWayLoc .
      bd:serviceParam wikibase:radius "1.5" .
    }

  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
  }
}

Try it!

How many states this US state borders

#added before 2016-10
SELECT ?state ?stateLabel ?borders
WHERE
{
	{
		SELECT ?state (COUNT(?otherState) as ?borders)
		WHERE
		{
		?state wdt:P31 wd:Q35657 .
		?otherState wdt:P47 ?state .
		?otherState wdt:P31 wd:Q35657 .
		}
		GROUP BY ?state
	}
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
	}
}        
ORDER BY DESC(?borders)

Try it!

Places that are below 10 meters above sea level

#added before 2016-10

#defaultView:Map
SELECT ?place ?location ?elev ?image
WHERE
{
  ?place p:P2044/psv:P2044 ?placeElev.
  ?placeElev wikibase:quantityAmount ?elev.
  ?placeElev wikibase:quantityUnit ?unit.
  bind(0.01 as ?km).
  filter( (?elev < ?km*1000 && ?unit = wd:Q11573)
       || (?elev < ?km*3281 && ?unit = wd:Q3710)
       || (?elev < ?km      && ?unit = wd:Q828224) ).
  ?place wdt:P625 ?location.
  optional { ?place wdt:P18 ?image }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}

Try it!

Globes used to represent coordinates

#added before 2016-10
 SELECT (count(?v) as ?c) ?globe
WHERE
{
	?v wikibase:geoGlobe ?globe
}
GROUP BY ?globe
ORDER BY DESC(?c)

Try it!

Places within 1km of the Empire State Building

#added before 2016-10
 SELECT ?place ?placeLabel ?location ?instanceLabel
WHERE
{
  wd:Q9188 wdt:P625 ?loc .
  SERVICE wikibase:around {
      ?place wdt:P625 ?location .
      bd:serviceParam wikibase:center ?loc .
      bd:serviceParam wikibase:radius "1" .
  }
  OPTIONAL {  	?place wdt:P31 ?instance  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
  BIND(geof:distance(?loc, ?location) as ?dist)
} ORDER BY ?dist

Try it!

Select French municipalities by INSEE code (select by identifier)

SELECT ?item ?itemLabel ?inseeCode {
  ?item wdt:P374 ?inseeCode .
  FILTER (?inseeCode in ("75056", "69123", "13055"))
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}

Try it!


Map and list of municipalities in The Netherlands

#Concise list & map of the 355 Dutch municipalities, their geo coordinates and their provinces, per 1-1-2019
#See also: 
#https://almanak.overheid.nl/organisaties/Gemeenten/ - 355 in aantal
#https://nl.wikipedia.org/wiki/Lijst_van_Nederlandse_gemeenten - 355 in aantal

#defaultView:Map
select ?muni ?muniLabel ?location where {
  ?muni p:P31 ?instanceOf; # Get statement because we need this later
        wdt:P625 ?location. # And location
  ?instanceOf ps:P31 wd:Q2039348. # P31 should be 'municipality of the Netherlands'
  minus { ?muni wdt:P31 wd:Q7265977. } # Don't show former municipalities
  minus { ?instanceOf pq:P582 ?endTime. } # And don't show municipalities that have an end time
  service wikibase:label { bd:serviceParam wikibase:language "nl". } # Show names in Dutch
}

Try it!


Emergency numbers by population using them

#added before 2016-10

#Lists emergency numbers and the total amount of people which can use them
#defaultView:BubbleChart
SELECT ?emergencyNumber ?emergencyNumberLabel ?tel ?population ?countries
WHERE
{
 ?emergencyNumber wdt:P31 wd:Q694554 .
  OPTIONAL{SELECT ?emergencyNumber (COUNT(?state) as ?countries) (SUM(?pop) as ?population) WHERE {
  	?state wdt:P2852 ?emergencyNumber .
  	OPTIONAL{?state wdt:P1082 ?pop} .
  	?state wdt:P31/wdt:P279* wd:Q6256
  } GROUP BY ?emergencyNumber } .
  OPTIONAL{?emergencyNumber wdt:P1329 ?tel }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
ORDER BY DESC(?population)

Try it!

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

#added before 2016-10

# German states, ordered by the number of company headquarters per million inhabitants
# Replace wd:Q1221156 (state of Germany) by anything else you care about, e.g., wd:Q6256 (country)
# Nested queries for correctness (don't count companies twice) and performance (aggregate before adding more data)
# Limits: states without population missing; company data in Wikidata is always incomplete
# Note: 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.
SELECT
	?state ?stateLabel
	?companies
	?population
	(?companies/?population*1000000 AS ?companiesPerM)
WHERE
{
	{ SELECT ?state (count(*) as ?companies) WHERE {
		{SELECT DISTINCT ?company ?state WHERE {
			?state wdt:P31 wd:Q1221156 .
			?company wdt:P31/wdt:P279* wd:Q4830453 .
			?company wdt:P159/wdt:P131* ?state .
			FILTER NOT EXISTS{ ?company wdt:P576 ?date } # don't count dissolved companies
		} }
	} GROUP BY ?state  }
    ?state wdt:P1082 ?population
	SERVICE wikibase:label { bd:serviceParam wikibase:language "de" }
}
ORDER BY DESC(?companiesPerM)

Try it!

Popular names per birthplace

#added before 2016-10

#defaultView:BubbleChart
SELECT ?cid ?firstname (COUNT(*) AS ?count)
WHERE
{
  ?pid wdt:P19 wd:Q64.
  ?pid wdt:P735 ?cid.
  OPTIONAL {
    ?cid rdfs:label ?firstname
    FILTER((LANG(?firstname)) = "en")
  }
}
GROUP BY ?cid ?firstname
ORDER BY DESC(?count) ?firstname
LIMIT 50

Try it!

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

#added before 2016-10

#defaultView:Map
SELECT DISTINCT ?item ?itemLabel ?ed ?edLabel ?auteurLabel (year(?dateCreation) as ?AnneeCreation) ?lieuLabel ?coord ?lien
WHERE
{
  ?item wdt:P136 wd:Q1164267 .    # genre :récit de voyage
  ?item  wdt:P31 wd:Q571 .        # nature : livre
  OPTIONAL{
    ?item wdt:P50 ?auteur .       # [option] auteur
  }
  OPTIONAL{
    ?item wdt:P571 ?dateCreation. # [option] date de création              
  }
 
  ?item  wdt:P840 ?lieu .         # lieu de l'action
  MINUS {?item  wdt:P840 wd:Q933} # (bug du Pôle Sud)
  ?lieu wdt:P625 ?coord .         # coordonnées géographiques du lieu
 
  {
    ?item wdt:P953 ?lien .        # URL, texte intégral disponible sur
    ?item wdt:P407 wd:Q150        # langue de l'œuvre : français
  }UNION{
    ?ed wdt:P629 ?item .          # édition du livre
    ?ed wdt:P953 ?lien .          # URL, texte intégral disponible sur 
    ?ed wdt:P407 wd:Q150          # langue de l'œuvre : français
  }

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr". }
} ORDER BY ?dateCreation

Try it!

Things located where the equator meets the prime meridian

#added before 2016-10

SELECT ?place ?placeLabel ?location
WHERE
{
  wd:Q24041662 wdt:P625 ?loc00 .
  SERVICE wikibase:around {
    ?place wdt:P625 ?location .
    bd:serviceParam wikibase:center ?loc00 .
    bd:serviceParam wikibase:radius "0.001" .
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" .  }
}
ORDER BY ?placeLabel

Try it!

French communes with names ending in ac

#added before 2016-10

#defaultView:Map
SELECT ?item ?itemLabel ?coord
WHERE
{
	?item	wdt:P31/wdt:P279* wd:Q484170;
				wdt:P17 wd:Q142;
				rdfs:label ?itemLabel;
				wdt:P625 ?coord;
	FILTER (lang(?itemLabel) = "fr").
	FILTER regex (?itemLabel, "ac$").
	FILTER not exists { ?item wdt:P131 wd:Q33788 } # excluding Koumac, New Caledonia...
}

Try it!

Buildings in more than one country

#added before 2016-10
SELECT ?item ?itemLabel ?count
WHERE
{
  {
    SELECT ?item (COUNT(DISTINCT ?country) AS ?count) WHERE {
      ?item wdt:P31/wdt:P279* wd:Q41176 .
      ?item wdt:P17 ?country .
      FILTER NOT EXISTS { ?country wdt:P576 ?end }
    }
    GROUP BY ?item
  }
  FILTER ( ?count > 1 )
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
ORDER BY DESC(?count) ?itemL

Try it!

Streets named after a person

SELECT ?street ?streetLabel ?cityLabel ?personLabel
WHERE
{
    ?street wdt:P31 wd:Q79007 .
    ?street wdt:P17 wd:Q142 .
    ?street wdt:P131 ?city .
    ?street wdt:P138 ?person .
    ?person wdt:P31 wd:Q5
    SERVICE wikibase:label { bd:serviceParam wikibase:language "fr" }
}
ORDER BY ?city

Try it!

Streets in France without a city

SELECT ?street ?streetLabel
WHERE
{
    ?street wdt:P31/wdt:P279* wd:Q79007 .
    ?street wdt:P17 wd:Q142 .
    MINUS { ?street wdt:P131 [] } .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "fr" }
}
ORDER BY ?streetLabel

Try it!

ATMs around Munich belonging to the Bankcard-Servicenetz interbank network (federated query)

#defaultView:Map{"hide":["?atm","?geometry"], "layer": "?bankLabel"}

PREFIX lgdo: <http://linkedgeodata.org/ontology/>
PREFIX geom: <http://geovocab.org/geometry#>
PREFIX bif: <bif:>

SELECT ?atm ?geometry ?bank ?bankLabel WHERE {
  hint:Query hint:optimizer "None".
  
  SERVICE <http://linkedgeodata.org/sparql> {
    { ?atm a lgdo:Bank; lgdo:atm true. }
    UNION { ?atm a lgdo:Atm. }
    
    ?atm geom:geometry [geo:asWKT ?geometry];
         lgdo:operator ?operator.
    FILTER(bif:st_intersects(?geometry, bif:st_point(11.5746898, 48.1479876), 5)) # 5 km around Munich
  }
  
  BIND(STRLANG(?operator, "de") as ?bankLabel) 
  ?bank rdfs:label ?bankLabel.
  
  # bank is part of the Bankcard service network, either via an explicit statement or implicitly due to its legal form (unless explicitly excluded)
  { ?bank wdt:P527 wd:Q806724. }
  UNION { ?bank wdt:P1454 wd:Q5349747. }
  MINUS { wd:Q806724 wdt:P3113 ?bank. }
}

Try it!

Items geographically located around the Wikimedia Foundation office, sorted by distance

SELECT ?place ?location ?distance ?placeLabel WHERE {
    SERVICE wikibase:around { 
      ?place wdt:P625 ?location . 
      bd:serviceParam wikibase:center "Point(-122.399523 37.786952)"^^geo:wktLiteral .
      bd:serviceParam wikibase:radius "1" . 
      bd:serviceParam wikibase:distance ?distance .
    } 
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY ?distance LIMIT 100

Try it!

Ten largest islands in the world

# Ten largest islands in the world
# Inspired by this infographic: https://redd.it/a6423t

#defaultView:ImageGrid
SELECT DISTINCT ?island ?islandLabel ?islandImage WHERE {
  # Instances of island (or of subclasses of island)
  ?island (wdt:P31/wdt:P279*) wd:Q23442.
  # Optionally with an image
  OPTIONAL { ?island wdt:P18 ?islandImage. }
  # Get the area of the island
  # Use the psn: prefix to normalize the values to a common unit of area
  ?island p:P2046/psn:P2046/wikibase:quantityAmount ?islandArea.
  # Use the label service to automatically fill ?islandLabel
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?islandArea)
LIMIT 10

Try it!

City gates in the Dutch province of Zeeland

select ?town ?townLabel ?gate ?gateLabel where {
  # Municipalities within the province 
  ?muni wdt:P31 wd:Q2039348;
        wdt:P131 wd:Q705.
  # Instances of city gate located within any of the municipalities
  ?gate wdt:P31 wd:Q82117;
        wdt:P131 ?muni;
  # The Location (usually Town) that the gate is in
        wdt:P276 ?town.
        
  SERVICE wikibase:label { bd:serviceParam wikibase:language "nl". }
}

Try it!


Demography

Birthplaces of humans named Antoine

#added before 2016-10

# Coordinates of the birth places of people named Antoine
#defaultView:Map
SELECT ?item ?itemLabel ?coord
WHERE
{
  ?item wdt:P31 wd:Q5 .   # human
  ?item wdt:P735 wd:Q15235674.
  ?item wdt:P19 ?place.
  ?place wdt:P625 ?coord.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
}

Try it!

Average lifespan by occupation

#added before 2016-10

# Select the desired columns and get labels
SELECT ?occ ?occLabel ?avgAge ?avgBirthYear ?count
WHERE
{
  {
    # Group the people by their occupation and calculate age
    SELECT
    	?occ
        (count(?p) as ?count)
        (round(avg(?birthYear)) as ?avgBirthYear)
        (avg(?deathYear - ?birthYear) as ?avgAge)
    WHERE {
      {
        # Get people with occupation + birth/death dates; combine multiple birth/death dates using avg
        SELECT
        	?p
            ?occ
            (avg(year(?birth)) as ?birthYear)
            (avg(year(?death)) as ?deathYear)
        WHERE {
           ?p  wdt:P31 wd:Q5 ;
              wdt:P106 ?occ ;
              p:P569/psv:P569 [
                wikibase:timePrecision "9"^^xsd:integer ; # precision of at least year
                wikibase:timeValue ?birth ;
              ] ;
              p:P570/psv:P570 [
                wikibase:timePrecision "9"^^xsd:integer ; # precision of at least year
                wikibase:timeValue ?death ;
              ] .
        }
        GROUP BY ?p ?occ
      }
    }
    GROUP BY ?occ
  }
 
  FILTER (?count > 300) # arbitrary number to weed out values with 'few' observations
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
ORDER BY ASC(?avgAge)

Try it!

Items with the most birth dates

SELECT ?person (COUNT(?date) AS ?dateC) {
  ?person wdt:P569 ?date
}
GROUP BY ?person
HAVING (?dateC > 2)
ORDER BY DESC (?dateC)
LIMIT 100

Try it!

Things/people with most children

#added before 2016-10
SELECT ?parent ?parentLabel ?count
WHERE
{
  {
    SELECT ?parent (COUNT(?child) AS ?count)
    WHERE
    {
      ?parent wdt:P40 ?child.
    }
    GROUP BY ?parent
    ORDER BY DESC(?count)
    LIMIT 10
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?count)
LIMIT 10

Try it!

Population growth in Suriname from 1960 onward

#defaultView:LineChart
SELECT ?year ?population {
  wd:Q730 p:P1082 ?p .
  ?p pq:P585 ?year ;
     ps:P1082 ?population .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?year

Try it!

Politics

Elections

The Netherlands

Candidates for the Dutch general election in 2017

The following query uses these:

  • Properties: Twitter username (P2002)  , P2035, candidacy in election (P3602)  , series ordinal (P1545)  , represents (P1268)  
     1 SELECT ?item ?itemLabel ?twitter ?LinkedIN ?politieke_partij ?politieke_partijLabel ?positie_op_lijst
     2 WHERE {
     3 	?item p:P3602 ?node .
     4     OPTIONAL { ?item wdt:P2002 ?twitter }
     5     OPTIONAL { ?item wdt:P2035 ?LinkedIN }
     6     ?node ps:P3602 wd:Q16061881 .
     7     OPTIONAL { ?node pq:P1545 ?positie_op_lijst }
     8     OPTIONAL { ?node pq:P1268 ?politieke_partij }
     9     OPTIONAL { ?node pq:P2035 ?LinkedIN }
    10 	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],nl" }
    11 }
    
Try it!
Gender distribution in the candidates for the Dutch general election 2017

The following query uses these:

  • Properties: sex or gender (P21)  , candidacy in election (P3602)  , series ordinal (P1545)  , represents (P1268)  
     1 #Kandidaten voor de Nederlandse tk verkiezingen van 2017
     2 #defaultView:Dimensions
     3 SELECT ?positie_op_lijst ?genderLabel ?politieke_partijLabel WHERE {
     4   ?item p:P3602 ?node.
     5   ?item wdt:P21 ?gender.
     6   ?node ps:P3602 wd:Q16061881 .
     7   ?node pq:P1545 ?positie_op_lijst.
     8   ?node pq:P1268 ?politieke_partij.
     9   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],nl". }
    10 }
    
Try it!
Candidates for the Dutch general election 2017 living in Antwerp, Belgium

The following query uses these:

  • Properties: residence (P551)  , Twitter username (P2002)  , P2035, candidacy in election (P3602)  , series ordinal (P1545)  , represents (P1268)  
     1 SELECT ?item ?itemLabel ?twitter ?LinkedIN ?politieke_partij ?politieke_partijLabel ?positie_op_lijst WHERE {
     2   ?item p:P3602 ?node.
     3   ?item wdt:P551 wd:Q12892.
     4   OPTIONAL { ?item wdt:P2002 ?twitter. }
     5   OPTIONAL { ?item wdt:P2035 ?LinkedIN. }
     6   ?node ps:P3602 wd:Q16061881.
     7   OPTIONAL { ?node pq:P1545 ?positie_op_lijst. }
     8   OPTIONAL { ?node pq:P1268 ?politieke_partij. }
     9   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],nl". }
    10 }
    
Try it!
Candidates for the Dutch general election 2017 living abroad

The following query uses these:

Features: Map (Q24515275)  

 1 #defaultView:Map
 2 SELECT ?item ?itemLabel ?coordinates WHERE {
 3   ?item p:P3602 ?node.
 4   ?item wdt:P551 ?residence .
 5   ?residence wdt:P17 ?country ;
 6              wdt:P625 ?coordinates .
 7   ?node ps:P3602 wd:Q16061881.
 8   FILTER (?country != wd:Q55)
 9   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],nl". }
10 }
Try it!
Occupations of candidates of the Dutch general election 2017

The following query uses these:

  • Properties: sex or gender (P21)  , occupation (P106)  , candidacy in election (P3602)  , series ordinal (P1545)  , represents (P1268)  
     1 #Kandidaten voor de Nederlandse TK verkiezingen van 2017
     2 #defaultView:Dimensions
     3 SELECT ?positie_op_lijst ?genderLabel ?occupationLabel ?politieke_partijLabel WHERE {
     4   VALUES ?politieke_partij {wd:Q747910 wd:Q275441}
     5   ?item p:P3602 ?node.
     6   ?item wdt:P21 ?gender.
     7   ?item wdt:P106 ?occupation.
     8   ?node ps:P3602 wd:Q16061881.
     9   ?node pq:P1545 ?positie_op_lijst.
    10   ?node pq:P1268 ?politieke_partij.
    11   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],nl". }
    12 }
    
Try it!

Gender balance of members of Irish parliament

#added before 2016-10
 SELECT ?genderlabel (COUNT(?genderlabel) as ?total)
WHERE
{
   ?subj wdt:P39 wd:Q654291  .
   ?subj wdt:P21 ?gender .
 
   ?gender rdfs:label ?genderlabel filter (lang(?genderlabel) = "en") .
   ?subj rdfs:label ?label filter (lang(?label) = "en")
}
GROUP BY ?genderlabel

Try it!

Assemblies by number of seats

#added before 2016-10

SELECT DISTINCT ?item ?title ?seats ?jurisdiction (YEAR(?inception) AS ?start) (YEAR(?dissolution) AS ?end)
WHERE
{
  ?item wdt:P31/wdt:P279* wd:Q1752346 .
  OPTIONAL { ?item wdt:P1342 ?seats . }
  OPTIONAL {
    ?item wdt:P1001 ?j .
    ?j rdfs:label ?jurisdiction filter (lang(?jurisdiction) = "en") .
  }
  OPTIONAL { ?item wdt:P571 ?inception . }
  OPTIONAL { ?item wdt:P576 ?dissolution . }
  OPTIONAL { ?item rdfs:label ?title filter (lang(?title) = "en") . }
}
ORDER BY DESC(?seats) ?title

Try it!

List of countries by age of the head of government

#added by Jura1, rev. 2016-11-08
SELECT DISTINCT ?age ?country ?countryLabel ?hgovernment ?hgovernmentLabel
{
	?country wdt:P31 wd:Q3624078 .
	FILTER NOT EXISTS {?country wdt:P31 wd:Q3024240}
	?country p:P6 ?statement .    
	?statement ps:P6 ?hgovernment .
	?country wdt:P6 ?hgovernment .
	FILTER NOT EXISTS { ?statement pq:P582 ?x } 
	?hgovernment wdt:P569 ?dob . BIND(YEAR(now())-YEAR(?dob) as ?age)
	FILTER(?age>=65)
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY DESC(?age)

Try it!

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

SELECT ?cc (COUNT(DISTINCT ?child) AS ?number) {
  ?child wdt:P31 wd:Q5 ; # Looking for real humans and not fictional ones
         wdt:P39/wdt:P279* wd:Q83307 ;
         (wdt:P22|wdt:P25) [wdt:P39/wdt:P279* wd:Q83307] ;
         wdt:P27/wdt:P901 ?cc
}
GROUP BY ?cc
ORDER BY DESC(?number)

Try it!

Members of the French National Assembly born out of France

#added before 2016-10

SELECT DISTINCT ?item ?itemLabel ?placeLabel ?countryLabel
WHERE
{
  ?item wdt:P39 wd:Q3044918 .
  ?item wdt:P19 ?place .
  ?place wdt:P17 ?country .
  FILTER NOT EXISTS { ?place wdt:P17 wd:Q142 . }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr" . }
}
ORDER BY ?countryLabel ?itemLabel

Try it!

List of parliament buildings with pictures by country

#added before 2016-10

#defaultView:ImageGrid
SELECT ?building ?buildingLabel ?country ?countryLabel ?picture
WHERE
{
	?building wdt:P31 wd:Q7138926 .
	?building wdt:P18 ?picture .
	OPTIONAL { ?building wdt:P17 ?country } .   #if available
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en" .
	}
}
ORDER BY ?countryLabel
LIMIT 188

Try it!

Number of jurisdictions by driving side

#added before 2016-10
SELECT ?sideLabel (COUNT(?jurisdiction) AS ?count)
WHERE
{
  ?jurisdiction wdt:P1622 ?side.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?sideLabel
ORDER BY ?sideLabel

Try it!

Timeline of mayors of Amsterdam, the Netherlands

#defaultView:Timeline
select ?mayor ?mayorLabel ?start ?end where {
  ?mayor p:P39 ?position.
  ?position ps:P39 wd:Q13423495;
            pq:P580 ?start;
            pq:P582 ?end.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],nl,en". }
}

Try it!

Current U.S. members of the Senate with district, party and date they assumed office

select ?senator ?senatorLabel ?districtLabel ?partyLabel ?assumedOffice (sample(?image) as ?image) where {
  # Get all senators
  ?senator p:P39 ?posheld; # With position held
           p:P102 ?partystatement. # And with a certain party
  
  # Get the party
  ?partystatement ps:P102 ?party.
  minus { ?partystatement pq:P582 ?partyEnd. } # but minus the ones the senator is no longer a member of
  minus { ?party wdt:P361 ?partOf. } # and the 'Minnesota Democratic–Farmer–Labor Party' and such
  
  # Check on the position in the senate
  ?posheld ps:P39 wd:Q4416090; # Position held is in the senate
           pq:P768 ?district;
           pq:P580 ?assumedOffice. # And should have a starttime
  
  minus { ?posheld pq:P582 ?endTime. } # But not an endtime 
  
  # Add an image
  optional { ?senator wdt:P18 ?image. }
         
  service wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} group by ?senator ?senatorLabel ?districtLabel ?partyLabel ?assumedOffice order by ?senatorLabel

Try it!

Economic and Business

Map of places of birth of dead economists, colour-coded by era

#defaultView:Map
SELECT DISTINCT ?person ?name ?birthplace ?birthyear ?coord ?layer WHERE {
{?person wdt:P106 wd:Q188094} UNION {?person wdt:P101 wd:Q8134}
?person wdt:P570 ?dod;
   wdt:P19 ?place .
?place wdt:P625 ?coord
OPTIONAL { ?person wdt:P569 ?dob }
BIND(YEAR(?dob) as ?birthyear)
BIND(IF( (?birthyear < 1700), "Pre-1700", IF((?birthyear < 1751), "1700-1750", IF((?birthyear < 1801), "1751-1800", IF((?birthyear < 1851), "1801-1850", IF((?birthyear < 1901), "1851-1900", IF((?birthyear < 1951), "1901-1950", "Post-1950") ) ) ) )) AS ?layer )
?person rdfs:label ?name filter (lang(?name) = "en")
?place rdfs:label ?birthplace filter (lang(?birthplace) = "en")
} ORDER BY ?birthyear

Try it!

Distinct Billionaires

# 2018-05-10: 93 results

SELECT ?locationLabel ?item ?itemLabel (MAX(?billions) as ?billions)
WHERE
{
  ?item wdt:P2218 ?worth.
  ?item wdt:P19 ?location .
  
  FILTER(?worth>1000000000).
  BIND(?worth/1000000000 AS ?billions).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,de". }
}
GROUP BY ?locationLabel ?item ?itemLabel
ORDER BY DESC(?billions)

Try it!

Science

Biology and Medicine

Diseases

The number of existing translations for diseases in Wikidata

Items used: disease (Q12136)

#added before 2016-10

SELECT ?disease ?doid ?enLabel (count(?language) as ?languages)
WHERE
{
	?disease wdt:P699 ?doid ;
             rdfs:label ?label ;
             rdfs:label ?enLabel .
    FILTER (lang(?enLabel) = "en")
   
    BIND (lang(?label) AS ?language)
}
group by ?disease ?doid ?enLabel
order by desc(?languages)

Try it!

A network of Drug-disease interactions on infectious diseases (Source: Disease Ontology, NDF-RT and ChEMBL)
#added before 2016-10
#defaultView:Graph
SELECT DISTINCT ?item ?itemLabel ?rgb ?link
WHERE
{
  VALUES ?toggle { true false }
  ?disease wdt:P699 ?doid;
           wdt:P279+ wd:Q18123741;
           wdt:P2176 ?drug.
  ?drug rdfs:label ?drugLabel.
		FILTER(LANG(?drugLabel) = "en").
  ?disease rdfs:label ?diseaseLabel.
		FILTER(LANG(?diseaseLabel) = "en").
  BIND(IF(?toggle,?disease,?drug) AS ?item).
  BIND(IF(?toggle,?diseaseLabel,?drugLabel) AS ?itemLabel).
  BIND(IF(?toggle,"FFA500","7FFF00") AS ?rgb).
  BIND(IF(?toggle,"",?disease) AS ?link).
}

Try it!

The number of Wikidata items on Diseases and the percentage of those with a pointer to the Disease Ontology
#added before 2016-10

SELECT (COUNT(?disease) AS ?total) (SUM(?ref) AS ?byDO) (100*?byDO/?total AS ?percent)
WHERE
{
  {?disease wdt:P31 wd:Q12136 }
  UNION
  {?disease wdt:P279 wd:Q12136 .}
  OPTIONAL {
    ?disease p:P699 ?statement.
    BIND(1 AS ?ref).
  }
}

Try it!

Genes

Human genes updated this week
SELECT DISTINCT ?item ?ncbi_gene ?date_modified
WHERE
{
	?item wdt:P351 ?ncbi_gene ;
          wdt:P703 wd:Q15978631 ;
          schema:dateModified ?date_modified .
    BIND (now() - ?date_modified as ?date_range)
    FILTER (?date_range < 8)
}

Try it!

Variants

Counts of gene-variant types sourced from the CIViC database
#defaultView:BarChart
SELECT  ?variant_typeLabel (count(?variant_typeLabel) as ?counts)
WHERE
{
	?item wdt:P3329 ?civic_id ;
          wdt:P31 ?variant_type .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
GROUP BY ?variant_typeLabel
ORDER BY ?counts

Try it!

Which variant of which gene predicts a positive prognosis in colorectal cancer
SELECT ?geneLabel ?variantLabel
WHERE
{ 
	VALUES ?disease {wd:Q188874}
    ?variant wdt:P3358 ?disease ; # P3358 Positive prognostic predictor
          wdt:P3433 ?gene . # P3433 biological variant of
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}

Try it!

Variants that are associated with renal cell carcinoma
# variants that are associated with renal cell carcinoma
SELECT DISTINCT ?civic_id ?item ?itemLabel
WHERE
{
	VALUES ?property {
                      wdt:P3356 # positive diagnostic predictor
                      wdt:P3357 # negative diagnostic predictor
                      wdt:P3358 # positive prognostic predicator
                      wdt:P3359 # negative prognostic predictor
                     }
    ?item wdt:P3329 ?civic_id .
    {?item  ?property wd:Q1164529.} # wd:Q1164529 = renal cell carcinoma
    UNION
    {?item p:P3354 ?o . # positive therapeutic predictor
     ?o pq:P2175 wd:Q1164529 .}
    UNION
    {?item p:P3354 ?o . # negative therapeutic predictor
     ?o pq:P2175 wd:Q1164529 .}
     
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}

Try it!

PubMed references in CIViCdb
# variants that are associated with renal cell carcinoma
SELECT DISTINCT  ?reference ?referenceLabel ?pmid
WHERE
{
	?item wdt:P3329 ?civicId ;
          ?property  ?object .
    ?object prov:wasDerivedFrom ?provenance .
    ?provenance pr:P248 ?reference .
    ?reference wdt:P31 wd:Q13442814 ;
               wdt:P698 ?pmid .
   
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}

Try it!

Variant counts by predictor type
#defaultView:BubbleChart
SELECT  ?propertyLabel (count(?prognostic_type) as ?counts)
WHERE
{
	VALUES ?prognostic_type {wdt:P3354 wdt:P3355 wdt:P3356 wdt:P3357 wdt:P3358 wdt:P3359}
    ?item wdt:P3329 ?civic_id ;
          ?prognostic_type ?prognostic_value .
    ?property wikibase:directClaim ?prognostic_type . 
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
GROUP BY ?propertyLabel ?prognostic_typeLabel
ORDER BY ?counts

Try it!

Proteins

Get Wikidata - UniprotId mappings for homo sapiens
SELECT ?item ?itemLabel ?uniprotid ?tax_node
WHERE
{
	?item wdt:P352 ?uniprotid ;
          wdt:P703 wd:Q15978631 .
   
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

Metabolites

Metabolites and the species where they are found in
PREFIX pr: <http://www.wikidata.org/prop/reference/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX prov: <http://www.w3.org/ns/prov#>

SELECT ?compound ?compoundLabel ?speciesLabel ?sourceLabel ?doi ?wpid WHERE {
  ?compound wdt:P31 wd:Q11173.
  MINUS { ?compound wdt:P31 wd:Q8054. }
  ?compound p:P703 ?statement.
  ?statement rdf:type wikibase:BestRank.
  ?statement ps:P703 ?species.
  OPTIONAL {
    ?statement (prov:wasDerivedFrom/pr:P248) ?source.
    OPTIONAL { ?statement (prov:wasDerivedFrom/pr:P2410) ?wpid. }
    OPTIONAL { ?statement (prov:wasDerivedFrom/pr:P356) ?doi. }
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ASC(?compound)

Try it!

Metabolite-metabolite interactions (mostly conversions) and their pKa change

Federated query using the WikiPathways SPARQL endpoint to retrieve interaction information. The dimensions plot show the pKa changes during metabolite-metabolite interaction. It must be noted here that many very basic or very acidic are reported in pathways as the uncharged structure, whereas in normal biological pathways these compounds are charged and then have quite different pKa charges.

#defaultView:Dimensions
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wp:    <http://vocabularies.wikipathways.org/wp#>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT DISTINCT ?wpid ?metaboliteLabel ?pKa ?pKa2 ?metabolite2Label ?wpid2
WITH {
  SELECT ?wpid ?source_pathway ?metabolite ?pKa ?pKa2 ?metabolite2 ?wpid2
  WHERE {
    # VALUES ?wpid { "WP550" }
    ?pathway wdt:P2410 ?wpid ;
             wdt:P527 ?metabolite ;
             wdt:P2888 ?source_pathway .
    ?metabolite wdt:P1117 ?pKa .

    SERVICE <http://sparql.wikipathways.org/> {
      ?wp_mb1 wp:bdbWikidata ?metabolite .
      ?wp_mb1 dcterms:isPartOf ?interaction .
      ?interaction rdf:type wp:Interaction .
      ?wp_mb2 dcterms:isPartOf ?interaction .
      ?wp_mb2 wp:bdbWikidata ?metabolite2 .
      FILTER (?wp_mb1 != ?wp_mb2)
    }
  }
} AS %result
WHERE {
  INCLUDE %result
  ?metabolite2 wdt:P1117 ?pKa2 .
  ?pathway2 wdt:P2410 ?wpid2 ;
             wdt:P527 ?metabolite2 ;
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

Taxon

Asterophryinae parent taxon reverse graph
#defaultView:Graph
PREFIX gas: <http://www.bigdata.com/rdf/gas#>

SELECT ?item ?itemLabel ?pic ?linkTo
WHERE
{
  SERVICE gas:service {
    gas:program gas:gasClass "com.bigdata.rdf.graph.analytics.SSSP" ;
                gas:in wd:Q1968598;
                gas:traversalDirection "Reverse" ;
                gas:out ?item ;
                gas:out1 ?depth ;
                gas:maxIterations 3 ;
                gas:linkType wdt:P171 .
  }
  OPTIONAL { ?item wdt:P171 ?linkTo }
  OPTIONAL { ?item wdt:P18 ?pic }
  SERVICE wikibase:label {bd:serviceParam wikibase:language "en" }
}

Try it!

Pathways

All human pathways from Wikipathways
SELECT ?pathway ?pathwayLabel ?wpid WHERE {
   ?pathway wdt:P2410 ?wpid ;
            wdt:P703 wd:Q15978631 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

Biomarkers in Wikidata which interact with proteins in human pathways from Wikipathways
prefix void:  <http://rdfs.org/ns/void#> 
prefix pav:   <http://purl.org/pav/> 
prefix xsd:   <http://www.w3.org/2001/XMLSchema#> 
prefix freq:  <http://purl.org/cld/freq/> 
prefix biopax: <http://www.biopax.org/release/biopax-level3.owl#> 
prefix skos:  <http://www.w3.org/2004/02/skos/core#> 
prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> 
prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
prefix gpml:  <http://vocabularies.wikipathways.org/gpml#> 
prefix wp:    <http://vocabularies.wikipathways.org/wp#> 
prefix dcterms: <http://purl.org/dc/terms/> 
prefix wprdf: <http://rdf.wikipathways.org/> 
prefix prov:  <http://www.w3.org/ns/prov#> 
prefix foaf:  <http://xmlns.com/foaf/0.1/> 
prefix dc:    <http://purl.org/dc/elements/1.1/> 

SELECT DISTINCT ?biomarkerLabel ?proteinLabel ?geneID ?WP_gene ?PathwayID ?PathwayName #results that are displayed.
WHERE {
  VALUES ?biomarker {wd:Q420633 wd:Q27125809 wd:Q422462} #you can add more biomarkers here if needed, separated by a space.
  ?biomarker wdt:P31 wd:Q11173. #Stating that all biomarkers have to be "instance of" "chemical compound" (you could ommit this, but query will probably take longer).
  ?biomarker wdt:P638 ?pdbID .  #Checking if a biomarker has a Protein Databank ID (PDB) -> meaning the metabolite can interact with a protein.
  ?protein wdt:P31 wd:Q8054 . #Stating that all proteins are "instance of" "protein"
  ?protein wdt:P638 ?pdbID . #Checking which proteins have a PDB ID, which we queried previously in relationship to the biomarkers.
  ?protein wdt:P702 ?gene . #Connecting the protein to a gene ("encoded by" relationship) -> to get an identifier we can use later in federated WikiPathways query.
  ?gene wdt:P703 wd:Q15978631 . #Now removing all genes that are not found in species "Homo sapiens". -> This info is not always available for proteins in WikiData.
  ?gene wdt:P2888 ?geneID . #Getting the "exact match" identifier for the gene, related to the protein, related to the biomarker.
    
  SERVICE <http://sparql.wikipathways.org/> { #Connecting to the WikiPathways SPARQL endpoint.
     ?WP_pathway a wp:Pathway . #Stating a ?WP_pathway is indeed a pathway in the WikiPathways RDF .
     ?WP_pathway wp:organismName "Homo sapiens"^^xsd:string . #Removing all PWs not for species Homo sapiens.
     ?WP_pathway dc:identifier ?PathwayID . #Query the identifier of the pathway in WPs.
     ?WP_pathway dc:title ?PathwayName . #Obtaining the name of the pathway. 
    
     ?WP_gene a wp:Protein . #Stating that a ?WP_gene is a Protein DataNode (you could ommit this, to also get all DataNodes modeled as GeneProducts out, but query will take longer).
     ?WP_gene wp:bdbEntrezGene ?geneID . #Connecting the previously queried "exact match" from WikiData to the NCBI/Entrez Gene ID in WPs. 
     ?WP_gene dcterms:isPartOf ?WP_pathway . #Connecting the WP_gene to the WP_pathway.
     
   }
 OPTIONAL {?biomarker rdfs:label ?biomarkerLabel. #Create a label (aka name) for the biomarkers in WikiData, without using the service query. 
FILTER(LANG(?biomarkerLabel) = "en").
}
   OPTIONAL {?protein rdfs:label ?proteinLabel. #Create a label(aka name) for the proteins in WikiData, without using the service query.
FILTER(LANG(?proteinLabel) = "en").
}
 
}
ORDER BY DESC (?biomarkerLabel) #Order results for biomarkers

Try it!

Ranking of most cited work in WikiPathways
SELECT ?citation ?citationLabel (count(?pathway) as ?times_cited) WHERE {
  ?pathway wdt:P2410 ?WikiPathwaysID ;
           wdt:P2860 ?citation .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  }
GROUP BY ?pathway ?citation ?citationLabel

Try it!

Gene and metabolite counts per pathway
#Gene and metabolite counts per path
#defaultView:ScatterChart
SELECT ?path ?genes ?metabolites ?pathway WHERE {
  {SELECT DISTINCT ?path (COUNT(?pwPart) AS ?genes) WHERE {
      ?path wdt:P2410 ?WikipathsID.
      ?path wdt:P527 ?pwPart.
      ?pwPart wdt:P31 wd:Q7187.
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    }
    GROUP BY ?path ?genes
  }
  {SELECT DISTINCT ?path (COUNT(?pwPart) AS ?metabolites) WHERE {
      ?path wdt:P2410 ?WikipathsID.
      ?path wdt:P527 ?pwPart.
      ?pwPart wdt:P31 wd:Q11173.
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    }
    GROUP BY ?path ?metabolites
  }
  OPTIONAL { ?path rdfs:label ?pathway. }
}
ORDER BY DESC(?genes)

Try it!

Biological pathways with protein structures in the PDB database
SELECT ?pathway ?pathwayLabel ?WikiPathways ?Reactome (COUNT(DISTINCT ?protein) as ?count) WHERE {
  VALUES ?pathwayType { wd:Q4915012 wd:Q2996394 }
  ?pathway wdt:P31 ?pathwayType .
  { ?pathway wdt:P527/wdt:P688 ?protein . } UNION { ?pathway wdt:P527 ?protein . }
  ?protein wdt:P638 ?PDBID .
  OPTIONAL { ?pathway wdt:P2410 ?WikiPathways }
  OPTIONAL { ?pathway wdt:P3937 ?Reactome }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} GROUP BY ?pathway ?pathwayLabel ?WikiPathways ?Reactome
  ORDER BY DESC(?count)

Try it!

Integration queries (with other sources)
Get known variants reported in CIViC database (Q27612411) of genes reported in a Wikipathways pathway: Bladder Cancer (Q30230812)

The following query uses these:

Try it!
Federated queries
Known interaction types in Wikipathways for a pathway with Identifier WP716
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX wp: <http://vocabularies.wikipathways.org/wp#>
SELECT DISTINCT ?interaction_type WHERE {
  VALUES ?wpid {"WP716"}
  ?item wdt:P2410 ?wpid ;
        wdt:P2888 ?source_pathway .
 
  SERVICE <http://sparql.wikipathways.org/> {
     ?wp_pathway dc:identifier ?source_pathway .
     ?s dcterms:isPartOf ?wp_pathway, ?interaction .
     ?interaction rdf:type wp:Interaction .
     ?interaction rdf:type ?interaction_type .
     ?interaction wp:participants ?participants .
  }
}

Try it!

Local annotations from Wikipathways using Federated query on a Pathway with identifier WP716

The following query uses these:

  • Properties: WikiPathways ID (P2410)  , exact match (P2888)  
     1 PREFIX dcterms: <http://purl.org/dc/terms/>
     2 PREFIX wp: <http://vocabularies.wikipathways.org/wp#>
     3 SELECT DISTINCT ?item ?pw_annotation  WHERE {
     4   VALUES ?wpid {"WP716"}
     5   ?item wdt:P2410 ?wpid ;
     6         wdt:P2888 ?source_pathway .
     7  
     8   SERVICE <http://sparql.wikipathways.org/> {
     9      ?wp_pathway dc:identifier ?source_pathway .
    10      ?wp_pathway wp:ontologyTag ?pw_annotation .
    11      # ?pw_annotation rdfs:label ?annotation_label .
    12    }
    13 }
    
Try it!

Find drugs for cancers that target genes related to cell proliferation

#added before 2016-10

#added before 2016-10; worked on 2018-12-17 :)

#cases where a drug physically interacts with the product of gene known to be genetically associated a disease
#these cases may show opportunities to repurpose a drug for a new disease
#See http://database.oxfordjournals.org/content/2016/baw083.long  and
#http://drug-repurposing.nationwidechildrens.org/search
#an example that was recently validated involved a new link between Metformin wd:Q19484 and cancer survival
#https://jamia.oxfordjournals.org/content/22/1/179
#currently set up to find drugs for cancers that target genes related to cell proliferation
#adapt by changing constraints (e.g. to 'heart disease' Q190805) or removing them
SELECT ?drugLabel ?geneLabel ?biological_processLabel ?diseaseLabel
WHERE {
  ?drug wdt:P129 ?gene_product .   # drug interacts with a gene_product
  ?gene wdt:P688 ?gene_product .  # gene_product (usually a protein) is a product of a gene (a region of DNA)
  ?disease	wdt:P2293 ?gene .    # genetic association between disease and gene
  ?disease wdt:P279*  wd:Q12078 .  # limit to cancers wd:Q12078 (the * operator runs up a transitive relation..)
  ?gene_product wdt:P682 ?biological_process . #add information about the GO biological processes that the gene is related to 
  
   ?biological_process (wdt:P361|wdt:P279)* wd:Q14818032 .  # chain down subclass/part-of
   #Change the last statement (wd:Q14818032) to limit to genes related to certain biological processes (and their sub-processes):
  		#cell proliferation wd:Q14818032 (Current example)
                #apoptosis wd:Q14599311

    #uncomment the next line to find a subset of the known true positives (there are not a lot of them in here yet; will lead to 4 drugs if biological process is cell proliferation 2018-12-17)
  #?disease wdt:P2176 ?drug . 	# disease is treated by a drug
  	SERVICE wikibase:label {
        bd:serviceParam wikibase:language "en" .
	}
}
LIMIT 1000

Try it!

Parent taxons of Blue Whale

#added before 2016-10

#defaultView:Graph
SELECT ?item ?itemLabel ?pic ?linkTo
WHERE
{
  wd:Q42196 wdt:P171* ?item
  OPTIONAL { ?item wdt:P171 ?linkTo }
  OPTIONAL { ?item wdt:P18 ?pic }
  SERVICE wikibase:label {bd:serviceParam wikibase:language "en" }
}

Try it!

Mosquito species

# Species of mosquitoes
# added 2017-06
SELECT ?item ?taxonname WHERE {
  ?item wdt:P31 wd:Q16521 ;
        wdt:P105 wd:Q7432 ;
        wdt:P171* wd:Q7367 ;
        wdt:P225 ?taxonname .
}

Try it!

Taxons and what they are named after

#added before 2016-10

SELECT ?taxon ?eponym ?taxonName ?eponymLabel
WHERE
{
  ?taxon wdt:P31 wd:Q16521;
         wdt:P225 ?taxonName;
         wdt:P138 ?eponym.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?eponym

Try it!

Biologists with Twitter accounts

SELECT DISTINCT ?personLabel (CONCAT("https://twitter.com/",?twitterName) AS ?twitterlink) ?pic
WHERE {
  ?person wdt:P2002 ?twitterName ;
    wdt:P106 ?occupation .
  OPTIONAL { ?person wdt:P18 ?pic . }
  ?occupation wdt:P279* wd:Q864503 . # all subclasses of biologists
   SERVICE wikibase:label {
     bd:serviceParam wikibase:language "en"
   }
}

Try it!

Cell lines with names that could also be URLs (Internet of Cell Lines).

SELECT * WHERE {
  {
    SELECT ?cell_line ?cell_line_name WHERE {
      ?cell_line wdt:P31 wd:Q21014462;
                 rdfs:label ?cell_line_name.
          FILTER(LANG(?cell_line_name) = "en").
          Filter REGEX(STR(?cell_line_name), "^[\\w\\-\\.]+\\.[A-z]+$")
    }
  }
  ?tld wdt:P31/wdt:P279* wd:Q14296;
       rdfs:label ?tld_name.
  FILTER(LANG(?tld_name) = "en").
  FILTER REGEX(STR(?cell_line_name), CONCAT(REPLACE(?tld_name, "\\.", "\\\\."), "$"), "i")
  BIND(URI(CONCAT("http://", ?cell_line_name)) as ?url)
}

Try it!

List of pharmaceutical drugs with picture

#added before 2016-10

SELECT ?moleculeLabel ?formule ?picture ?molecule
WHERE
{
	?molecule  wdt:P31 wd:Q12140
	; wdt:P274 ?formule
	; wdt:P117 ?picture 
	SERVICE wikibase:label {  bd:serviceParam wikibase:language "en, de" . }
}
ORDER BY ?moleculeLabel

Try it!

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

#added before 2016-10

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") .   
}

Try it!

Computer Science and Technology

List of computer files formats

#added before 2016-10

SELECT DISTINCT ?idExtension ?extension ?mediaType ?idExtensionLabel
WHERE
{
	?idExtension wdt:P31 wd:Q235557
	; wdt:P1195 ?extension .
	OPTIONAL { ?idExtension wdt:P1163 ?mediaType }
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?extension ?mediaType

Try it!

List of W3C standards

#added before 2016-10

SELECT DISTINCT ?standard ?standardLabel ?website
WHERE
{
        ?standard wdt:P1462 wd:Q37033 .
        OPTIONAL{ ?standard wdt:P856 ?website }
        SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?standardLabel

Try it!

Oldest software

SELECT ?software ?softwareLabel ?date (ROUND((NOW() - ?date)/365.2425) AS ?age)
{
  ?software wdt:P31/wdt:P139* wd:Q7397.
  OPTIONAL { ?software wdt:P571 ?date. }
  OPTIONAL { ?software p:P348/pq:P577 ?date. }
  FILTER(BOUND(?date)).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?date
LIMIT 10

Try it!

Universities of main programming language authors

SELECT ?lang ?langLabel ?human ?humanLabel ?educatedat ?educatedatLabel ?coords
{
  ?lang wdt:P31/wdt:P279* wd:Q9143 .
  ?human wdt:P31 wd:Q5 .
  { ?lang wdt:P287 ?human } UNION { ?lang wdt:P170 ?human } UNION { ?lang wdt:P943 ?human } UNION { ?lang wdt:P178 ?human } .

  ?human wdt:P69 ?educatedat .
  ?educatedat wdt:P625 ?coords .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,fr" }
}
LIMIT 100

Try it!

Websites with OpenAPI endpoints

SELECT ?database ?databaseLabel ?license ?licenseLabel ?value WHERE {
  ?database ?p ?wds .
  OPTIONAL { ?database wdt:P275 ?license }
  ?wds ?v ?value.
  ?wdP wikibase:statementProperty ?v.
  ?wdP wikibase:claim ?p.
  ?wds pq:P31 wd:Q27075870.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
} ORDER BY ASC(?databaseLabel)

Try it!

E-Readers that support the mobipocket file format

SELECT ?ereader ?ereaderLabel

WHERE {
  ?ereader wdt:P31  wd:Q726235 .
  ?ereader wdt:P1072 wd:Q1941622 .
 
  SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en" .
   
}
  }

Try it!

Software applications ranked in descending order by the number of writable file formats

#defaultView:BubbleChart 
SELECT ?app ?appLabel (COUNT(?format) AS ?count)
WHERE {
  ?app (p:P31/ps:P31/wdt:P279) wd:Q7397 .
  ?app wdt:P1072 ?format .
            
  SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en" .
    
}
  }

GROUP BY ?app ?appLabel
ORDER BY DESC(?count)

Try it!

Return a bubble chart of mediatypes by count of file formats

SELECT DISTINCT ?mediaType (COUNT (?ff) as ?count)
WHERE
{
	?ff wdt:P31/wdt:P279* wd:Q235557.
	?ff wdt:P1163 ?mediaType.
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

GROUP BY ?mediaType 
ORDER BY DESC (?count)

Try it!

Erdos Numbers and images of people who have oral histories in the Computer History Museum's collection

#defaultView:ImageGrid
SELECT  ?personLabel  ?image ?Erdos

WHERE {
  ?person wdt:P485 wd:Q964035 .
  ?person wdt:P18 ?image .
  ?person wdt:P2021 ?Erdos
  SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en" .
   
}
  }

Try it!

Chemistry

Chemical elements and their properties

#added before 2016-10

SELECT ?elementLabel ?_boiling_point ?_melting_point ?_electronegativity ?_density ?_mass
WHERE
{
  ?element wdt:P31 wd:Q11344.
  ?element wdt:P2102 ?_boiling_point.
  ?element wdt:P2101 ?_melting_point.
  ?element wdt:P1108 ?_electronegativity.
  ?element wdt:P2054 ?_density.
  ?element wdt:P2067 ?_mass.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 100

Try it!

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

#added before 2016-10

SELECT ?element (SAMPLE(?symbol) AS ?symbol) (SAMPLE(?protons) AS ?protons) (MIN(?neutrons) AS ?minNeutrons) (MAX(?neutrons) AS ?maxNeutrons)
WHERE
{
  ?element wdt:P31 wd:Q11344;
           wdt:P1086 ?protons;
           wdt:P246 ?symbol.
  ?isotope wdt:P279 ?element;
           wdt:P1148 ?neutrons.
}
GROUP BY ?element
ORDER BY ?protons

Try it!

Colors of chemical compounds

#added before 2016-10

#defaultView:BubbleChart
SELECT ?rgb ?colorLabel (COUNT(?compound) AS ?count)
WHERE
{
  ?compound wdt:P31 wd:Q11173;
            wdt:P462 ?color.
  OPTIONAL { ?color wdt:P465 ?rgb. }
  BIND(IF(BOUND(?rgb),?rgb,"CCCCCC") AS ?rgb).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?rgb ?colorLabel

Try it!

All pKa data in Wikidata and the source titles

#added before 2016-10

SELECT ?compound ?compoundLabel ?pKa ?source ?sourceLabel ?doi
WHERE
{
  ?compound wdt:P31 wd:Q11173 ; p:P1117 ?statement .
  ?statement rdf:type wikibase:BestRank ;
    ps:P1117 ?pKa .
  OPTIONAL {
    ?statement prov:wasDerivedFrom/pr:P248 ?source .
    OPTIONAL { ?source wdt:P356 ?doi . }
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } #English label
}

Try it!

All CAS registry numbers in Wikidata

#added before 2016-10

SELECT DISTINCT ?compound ?compoundLabel ?cas
WHERE
{
  ?compound wdt:P231 ?cas .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

Chemical compounds in Wikidata sharing the same CAS registry number

#added before 2016-10

#two chemical compounds with the same CAS registry number
SELECT DISTINCT ?cas ?compound1 ?compound1Label ?compound2 ?compound2Label WHERE {
  ?compound1 wdt:P231 ?cas .
  ?compound2 wdt:P231 ?cas .
  FILTER (?compound1 != ?compound2)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

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

#added before 2016-10

#The number of times a cas registry number is shared by distinct Wikidata items
SELECT ?cas ?items
WHERE
{
	{SELECT DISTINCT ?cas (count(?compound) as ?items) WHERE {
  		?compound wdt:P231 ?cas .
	}
    GROUP BY ?cas }
    FILTER (?items >1)
}
ORDER BY desc(?items)

Try it!

Awarded Chemistry Nobel Prizes

#defaultView:Timeline
SELECT DISTINCT ?item ?itemLabel ?when (YEAR(?when) as ?date) ?pic
WHERE {
  ?item p:P166 ?awardStat . # … with an awarded(P166) statement
  ?awardStat ps:P166 wd:Q44585 . # … that has the value Nobel Prize in Chemistry (Q35637)
  ?awardStat pq:P585 ?when . # when did they receive the Nobel prize
 
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
OPTIONAL { ?item wdt:P18 ?pic }
}

Try it!

Images of organic acids

#defaultView:ImageGrid
SELECT ?compound ?compoundLabel ?image WHERE {
  ?compound wdt:P279+|wdt:P31+ wd:Q421948 ;
            wdt:P18|wdt:P117 ?image .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

Boiling points of alkanes

SELECT DISTINCT ?comp ?compLabel ?formula ?bp ?bpUnit ?bpUnitLabel WHERE {
  ?comp wdt:P31/wdt:P279* wd:Q41581 ;
        wdt:P274 ?formula ;
        p:P2102 [
          ps:P2102 ?bp ;
          psv:P2102/wikibase:quantityUnit  ?bpUnit
        ] .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY DESC(?bpUnit) ASC(?bp)
}

Try it!

Solubilities of chemicals

SELECT DISTINCT ?chemical ?chemicalLabel ?value ?units ?unitsLabel ?solvent ?solventLabel ?temperature ?temperatureUnit ?temperatureUnitLabel ?source ?sourceLabel ?doi
WITH {
  SELECT DISTINCT ?chemical ?value ?units ?source ?doi ?solvent ?temperature ?temperatureUnit WHERE {
    ?chemical ?propp ?statement .
    ?statement a wikibase:BestRank ;
      ?proppsv [
        wikibase:quantityAmount ?value ;
        wikibase:quantityUnit ?units
      ] .
    OPTIONAL {
      ?statement prov:wasDerivedFrom/pr:P248 ?source .
      OPTIONAL { ?source wdt:P356 ?doi . }
    }
    ?property wikibase:claim ?propp ;
            wikibase:statementValue ?proppsv ;
            wdt:P1629 wd:Q170731 ;
            wdt:P31 wd:Q21077852 .
    OPTIONAL {
      ?statement pqv:P2076 ?temperatureNode .
      ?temperatureNode wikibase:quantityAmount ?temperature ;
                       wikibase:quantityUnit ?temperatureUnit .  
    }
    OPTIONAL {
      wd:P2178 wikibase:qualifier ?qualifierS .
      ?qualifierS a owl:ObjectProperty .
      ?statement ?qualifierS ?solvent .
    }
  } GROUP BY ?chemical ?value ?units ?temperature ?temperatureUnit ?solvent ?source ?doi
} AS %result
WHERE {
  INCLUDE %result
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} 
ORDER BY ASC(?propEntityLabel)
}

Try it!

Space

Who discovered the most asteroids?

#added before 2016-10
SELECT ?discoverer ?name (COUNT(?asteroid) AS ?count)
WHERE
{
	?asteroid wdt:P31 wd:Q3863 .
	?asteroid wdt:P61 ?discoverer .
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
		?discoverer rdfs:label ?name
	}
}
GROUP BY ?discoverer ?name
ORDER BY DESC(?count)
LIMIT 20

Try it!

Who discovered the most planets? (with list)

#added before 2016-10
SELECT
	?discoverer ?discovererLabel 
	(COUNT(DISTINCT ?planet) as ?count)
	(GROUP_CONCAT(DISTINCT(?planetLabel); separator=", ") as ?planets)
WHERE
{
	?ppart wdt:P279* wd:Q634 .
	?planet wdt:P31 ?ppart .
	?planet wdt:P61 ?discoverer .
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en" .
		?discoverer rdfs:label ?discovererLabel .
		?planet rdfs:label ?planetLabel           
	}
}
GROUP BY ?discoverer ?discovererLabel
ORDER BY DESC(?count)

Try it!

List of space probes with pictures

#added before 2016-10

#defaultView:ImageGrid
SELECT ?spaceProbeLabel ?date ?picture
WHERE
{
	?spaceProbe wdt:P31 wd:Q26529;
        wdt:P18 ?picture;
        wdt:P619 ?date . #mandatory
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "fr,en" .
	}
}
ORDER BY ?date
LIMIT 88

Try it!

Birthplaces of astronauts

#added before 2016-10

# select all astronauts with name, image, birthdate, birthplace and coordinates of the birthplace

SELECT ?astronaut ?astronautLabel ?image ?birthdate ?birthplace ?coord WHERE {
  ?astronaut ?x1 wd:Q11631;
  wdt:P18 ?image;
  wdt:P569 ?birthdate;
  wdt:P19 ?birthplace.
 
  ?birthplace wdt:P625 ?coord
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?birthdate)

Try it!

(Artist) Images of Exoplanets

#defaultView:ImageGrid
SELECT ?exoplanet ?exoplanetLabel ?image WHERE {
  ?exoplanet wdt:P31 wd:Q44559 ;
             wdt:P18 ?image .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

Scientists

Number of scientists per gender

#added before 2016-10
SELECT ?gender (count(distinct ?human) as ?number)
WHERE
{
	?human wdt:P31 wd:Q5
	; wdt:P21 ?gender
	; wdt:P106/wdt:P279* wd:Q901 .
}
GROUP BY ?gender
LIMIT 10

Try it!

Most eponymous mathematicians

#added before 2016-10

SELECT ?eponym ?eponymLabel ?count ?sample ?sampleLabel
WHERE
{
	{
	SELECT ?eponym (COUNT(?item) as ?count) (SAMPLE(?item) AS ?sample)
	WHERE
	{
		?item wdt:P138 ?eponym.
		?eponym wdt:P106 wd:Q170790.
	}
	GROUP BY ?eponym
	}
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY DESC(?count)

Try it!

Authors of scientific articles by occupation

#added before 2016-10

#defaultView:BubbleChart
SELECT ?occupationLabel (count(DISTINCT ?author) as ?count)
WHERE
{
        ?object wdt:P31 wd:Q13442814
        ; wdt:P50 ?author .
        ?author wdt:P106 ?occupation .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en,fr" }
}
GROUP BY ?occupationLabel
ORDER BY DESC(?count)

Try it!

Authors of scientific articles who received a Nobel prize

#added in 2016-10

#Authors of scientific articles who received a Nobel prize
SELECT ?item ?itemLabel ?person ?personLabel ?_image ?award ?awardLabel
WHERE {
  ?person wdt:P166 ?award ; #person received an award
          wdt:P31 wd:Q5 . #person is instance of human
  ?award wdt:P31/wdt:P279* wd:Q7191 . #award is a Nobel Prize
  ?item wdt:P50 ?person ; #person is an author of item
        wdt:P31 wd:Q13442814 . #item is a scientific article
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
 
OPTIONAL { ?person wdt:P18 ?_image. } #Wikimedia Commons has an image of person
}

Try it!

Using VALUES for extracting scientific articles of specific authors

SELECT ?entity ?entityLabel ?authorLabel WHERE {
  VALUES ?author {wd:Q18016466} #initialize "?author with the Wikidata item "Lydia Pintscher" 
  ?entity wdt:P31 wd:Q13442814. #filter by scientific articles
  ?entity wdt:P50 ?author.
 SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 
}

Try it!

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

#added before 2016-10
#Female scientists with most number of sitelinks (but not English Wikipedia)
#PREFIX schema: <http://schema.org/>

SELECT ?item ?itemLabel ?linkcount WHERE {
    ?item wdt:P31 wd:Q5 .
    ?item wdt:P21 wd:Q6581072 .
    ?item wdt:P106 wd:Q901 .
    ?item wikibase:sitelinks ?linkcount .
  FILTER (?linkcount >= 1) .       # only include items with 1 or more sitelinks
  FILTER NOT EXISTS {
    ?article schema:about ?item .
    ?article schema:inLanguage "en" .
    ?article schema:isPartOf <https://en.wikipedia.org/>
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,de,es,ar,fr" }
}
GROUP BY ?item ?itemLabel ?linkcount
ORDER BY DESC(?linkcount)

Try it!

Inventors killed by their own invention

#added before 2016-10
SELECT ?inventor ?inventorLabel ?gadget ?gadgetLabel WHERE {
  ?inventor wdt:P157 ?gadget.
  ?gadget wdt:P61 ?inventor.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

Most cited female authors

#added 2016-12
##defaultView:BubbleChart
SELECT ?author ?authorLabel (COUNT(?publication) AS ?count)
WHERE
{
    ?item wdt:P2860 ?publication . #citations
    ?publication wdt:P50 ?author . #authors
    ?author wdt:P21 wd:Q6581072. #females
    SERVICE wikibase:label {
        bd:serviceParam wikibase:language "en" .
    }
}
GROUP BY ?author ?authorLabel
ORDER BY DESC(?count)

Try it!

Scientists who have worked together but whose Erdos numbers don’t reflect that

#added before 2016-10

# Finds authors who have published scientific articles together,
# but whose Erdos numbers are more than one apart.
# These would appear to violate the definition of the Erdos number.

SELECT
	# Q#s
	?paper
	?author1
	?author2
	# title (either from title statement or label)
	(IF(BOUND(?title), ?title, ?paperLabel) AS ?title)
	# author labels (should be names) and their Erdos numbers
	?author1Label
	?erdos1
	?author2Label
	?erdos2
	# distance between Erdos numbers
	?distance
WHERE
{
	# paper, instance of or subclass of scientific article; also has two authors
	?paper wdt:P31/wdt:P279* wd:Q13442814;
	         wdt:P50 ?author1, ?author2.
	# if it has a title, we’ll grab that as well, but it’s also okay if there’s no title
	OPTIONAL { ?paper wdt:P1476 ?title. }
	# grab Erdos numbers of the two authors
	?author1 wdt:P2021 ?erdos1.
	?author2 wdt:P2021 ?erdos2.
	# introduce a new variable for the difference of the Erdos numbers
	BIND(?erdos2 - ?erdos1 AS ?distance).
	# select those cases where the distance is > 1
	# (note: by *not* taking the absolute value of the distance, we avoid getting duplicated cases because the author variables might be swapped)
	FILTER(?distance > 1).
	# get *Label variables automagically
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
# sort by distance first (descending), then by first author, then by second author
ORDER BY DESC(?distance) ?author1Label ?author2Label

Try it!

Map of institutions where Canadian citizens got their PhD

Map of institutions where Canadian citizens got their PhD - screenshot of the query results as of 2018-08-01.
#defaultView:Map
SELECT DISTINCT ?institution ?institutionLabel ?academics ?academicsLabel ?degree ?degreeLabel ?geoloc  ?image WHERE {
  ?academics wdt:P31 wd:Q5 ; # instances (P31) of humans (Q5)
             wdt:P27 wd:Q16 ; # country of citizenship
             p:P69 ?statement . # check for an "educated at" (P69) statement
  OPTIONAL { ?academics wdt:P18 ?image }. #image
  
  ?statement ps:P69 ?institution . # get value of the "educated at" statement, i.e. the institution
  ?institution wdt:P625 ?geoloc . # get the geolocation of the institution

  ?statement pq:P512 ?degree . # get qualifier "academic degree" (P512) 
  ?degree wdt:P31/wdt:P279* wd:Q849697 . # filter for doctoral degrees
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }

}

Try it!

Scientific literature

PMID-DOI mappings

#added before 2016-10

SELECT DISTINCT ?pmid ?doi
WHERE
{
	?item wdt:P698 ?pmid ;
              wdt:P356 ?doi .
}

Try it!

The number of statements by DOI

SELECT ?doi (COUNT (?entry) as ?entries)
{
  ?entry ?p ?statement .
  ?statement prov:wasDerivedFrom/pr:P248/wdt:P356 ?doi .
}
GROUP BY ?doi
ORDER BY DESC(?entries)

Try it!

number of statements backed by a reference with a DOI

#added before 2016-10

SELECT (COUNT (?statement) as ?statements)
WHERE
{
  ?entry ?p ?statement .
  ?statement prov:wasDerivedFrom/
       <http://www.wikidata.org/prop/reference/P248>/
       wdt:P356 ?doi .
}

Try it!

Statements originating from a specific DOI

#added before 2016-10

SELECT ?entryRes ?entry ?statement
WHERE
{
  ?entryRes ?p ?statement ;
    rdfs:label ?entry .
  ?statement prov:wasDerivedFrom/
       <http://www.wikidata.org/prop/reference/P248>/
       wdt:P356 "10.1021/JA01577A030" .
   FILTER(lang(?entry) = "en")
}

Try it!

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

SELECT ?English ?language ?label WHERE {
	?disease wdt:P699 "DOID:399";
             rdfs:label ?English;
             rdfs:label ?label .
	BIND(LANG(?label) as ?languageCode)
	?wdLanguage wdt:P424 ?languageCode;
	            rdfs:label ?language .
    FILTER EXISTS {?wdLanguage wdt:P31?/wdt:P279+ wd:Q17376908}
	FILTER (LANG(?English)="en")  
	FILTER (LANG(?language)="en")             
} ORDER BY ?language

Try it!

Library and Information Science journals

#added before 2016-10

SELECT DISTINCT ?journal ?name WHERE {
    ?journal wdt:P31 wd:Q5633421 . # is scientific journal
    {
            { ?journal wdt:P921 wd:Q199655 }   # with topic library science
      UNION { ?journal wdt:P921 wd:Q16387 }    # and/or topic information science
      UNION { ?journal wdt:P921 wd:Q13420675 } # and/or topic library and information science  
    }
    SERVICE wikibase:label {
        bd:serviceParam wikibase:language "en" .
        ?journal rdfs:label ?name .
    }
}

Try it!

Most popular subjects of scientific articles

select (count(?work) as ?count) ?subject ?subjectLabel where {
  ?work wdt:P31 wd:Q13442814;
        wdt:P921 ?subject .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
group by ?subject ?subjectLabel
order by desc(?count)
limit 200

Try it!

Scientific journals with editors on Twitter

SELECT ?journal ?journalLabel ?editor ?editorLabel ?twitter ?ex_publisher ?ex_publisherLabel
WITH {
  SELECT ?journal ?editor ?twitter (SAMPLE(?publisher) AS ?ex_publisher) WHERE {
    ?journal wdt:P31 wd:Q5633421 ; wdt:P98 ?editor .
    OPTIONAL { ?journal wdt:P123 ?publisher }
    ?editor wdt:P2002 ?twitter .
  } GROUP BY ?journal ?editor ?twitter
} AS %result
WHERE {
  INCLUDE %result
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY ?journalLabel

Try it!

Math

Mathematical proofs

#added before 2016-10

SELECT ?proof ?proofLabel
WHERE
{
  ?proof wdt:P31 wd:Q11538.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

Databases listed in Wikidata and if available applicable licenses

#added before 2016-10

SELECT DISTINCT *
WHERE
{
	?item 	wdt:P31 wd:Q8513 ;
		rdfs:label ?name .
	OPTIONAL {	?item  wdt:P275 ?licenseItem .
			?licenseItem rdfs:label ?license .
			FILTER (LANG(?license) = "en")}
	FILTER (LANG(?name) = "en")	
}

Try it!

Fictional universes with most fictional planets

#added before 2016-10

SELECT ?universe (SAMPLE(?label) AS ?label) (COUNT(?planet) AS ?count)
WHERE
{
  ?planet wdt:P31 wd:Q2775969;
          wdt:P1080 ?universe.
  ?universe rdfs:label ?label.
  FILTER(LANG(?label) = "en").
}
GROUP BY ?universe
ORDER BY DESC(?count)

Try it!

Objects with most mass

The following query uses these:

  • Properties: instance of (P31)  , mass (P2067)  
     1 SELECT ?object ?objectLabel ?mass WHERE {
     2   {
     3     SELECT ?object (MAX(?mass) AS ?mass) WHERE {
     4       ?object p:P2067/psn:P2067/wikibase:quantityAmount ?mass.
     5       MINUS { ?object wdt:P31 wd:Q3647172. }
     6     }
     7     GROUP BY ?object
     8     ORDER BY DESC(?mass)
     9     LIMIT 100
    10   }
    11   SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    12 }
    13 ORDER BY DESC(?mass)
    
Try it!

Biological databases listed in Wikidata and, if available, applicable licenses

SELECT ?item ?itemLabel ?url ?licence ?licenceLabel
WHERE {
  ?item wdt:P31 wd:Q4117139.
  OPTIONAL { ?item wdt:P856 ?url }
  OPTIONAL { ?item wdt:P275 ?licence }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
} ORDER BY ?itemLabel

Try it!

American universities founded before the states they reside in were created

SELECT ?uLabel ?founded ?stateLabel ?stateStart
WHERE {
	?u wdt:P31/wdt:P279* wd:Q3918 ;
       wdt:P131+ ?state ;
       wdt:P571 ?founded .
	?state wdt:P31 wd:Q35657 ;
           wdt:P571 ?stateStart .
	FILTER (?founded < ?stateStart) .
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
	}
}
LIMIT 10

Try it!

Universities ranked by PageRank on English Wikipedia (federated query)

PREFIX vrank:<http://purl.org/voc/vrank#>

SELECT DISTINCT ?uni ?uniLabel ?pr WHERE {
  ?uni wdt:P31/wdt:P279* wd:Q3918.
  SERVICE <http://dbpedia.org/sparql> {
    ?uni vrank:hasRank/vrank:rankValue ?pr
  }
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
  }
} ORDER BY DESC(?pr) LIMIT 50

Try it!

History

US presidents and spouses

#added before 2016-10
#TEMPLATE={"template":"Presidents of ?country and their spouses","variables":{"?country":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q6256 . }"} } }

SELECT ?p ?pLabel ?ppicture ?w ?wLabel ?wpicture WHERE {
  BIND(wd:Q30 AS ?country)
  ?country (p:P6/ps:P6) ?p.
  ?p wdt:P26 ?w.
  OPTIONAL {
    ?p wdt:P18 ?ppicture.
    ?w wdt:P18 ?wpicture.
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

US presidents & causes of death

List of presidents with causes of death

SELECT ?h ?hLabel ?cause ?causeLabel (YEAR(?date) AS ?year) WHERE {
?h wdt:P39 wd:Q11696;
   wdt:P509 ?cause;
   wdt:P570 ?date
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY ?year

Try it!

Presidents and their causes of death ranking

#added before 2016-10

#defaultView:BubbleChart
SELECT ?cid ?cause (count(*) as ?count)
WHERE
{
	?pid wdt:P39 wd:Q11696 .
	?pid wdt:P509 ?cid .
	OPTIONAL {
		?cid rdfs:label ?cause filter (lang(?cause) = "en") .
	}
}
GROUP BY ?cid ?cause
ORDER BY DESC(?count) ASC(?cause)

Try it!

Politicians who died of cancer (of any type)

#added before 2016-10
SELECT ?politician ?cause ?politician_label ?cause_of_death_label
WHERE
{
	?politician wdt:P106 wd:Q82955 .    # find items that have "occupation (P106): politician (Q82955)"
	?politician wdt:P509 ?cause .       # with a P509 (cause of death) claim
	?cause wdt:P279* wd:Q12078 .        # ... where the cause is a subclass of (P279*) cancer (Q12078)
	# ?politician wdt:P39 wd:Q11696 .   # Uncomment this line to include only U.S. Presidents
	 
	OPTIONAL {?politician rdfs:label ?politician_label filter (lang(?politician_label) = "en") .}
	OPTIONAL {?cause rdfs:label ?cause_of_death_label filter (lang(?cause_of_death_label) = "en").}
}
ORDER BY ASC (?politician)

Try it!

List of popes

#added before 2016-10

SELECT ?link ?linkLabel ?picture ?age
WHERE
{
	?link wdt:P31 wd:Q5 ;
          p:P39 [ ps:P39 wd:Q19546 ; pq:P580 ?startTime ] .
	OPTIONAL { ?link wdt:P569 ?dateOfBirth }
	OPTIONAL { ?link wdt:P18 ?picture }
	OPTIONAL { ?link wdt:P570 ?dateOfDeath }
	BIND(YEAR(?dateOfDeath) - YEAR(?dateOfBirth) as ?age)
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr,en" }
}
ORDER BY DESC(?startTime)

Try it!

Years with 3 popes

#added before 2016-10

SELECT ?year ?pope1Label ?pope2Label ?pope3Label
WHERE
{
  ?pope2 p:P39 [
           ps:P39 wd:Q19546;
           pq:P580 ?p2s;
           pq:P582 ?p2e;
           pq:P1365 ?pope1;
           pq:P1366 ?pope3
         ].
  ?pope1 p:P39 [
           ps:P39 wd:Q19546;
           pq:P582 ?p1e
         ].
  ?pope3 p:P39 [
           ps:P39 wd:Q19546;
           pq:P580 ?p3s
         ].
  BIND(YEAR(?p2s) AS ?year).
  FILTER(YEAR(?p2e) = ?year && YEAR(?p1e) = ?year && YEAR(?p3s) = ?year).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?year

Try it!

Popes with children

#added before 2016-10

# All popes with number of children
SELECT  (SAMPLE(?father) as ?father) ?fatherLabel  (SAMPLE(?picture) as ?picture) (COUNT(?father) as ?children)
WHERE
{
	?subj wdt:P22 ?father .
  	?father wdt:P31 wd:Q5 .
  	?father wdt:P39 wd:Q19546 .
	OPTIONAL {
		?father wdt:P18 ?picture .
		}
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
GROUP BY ?fatherLabel
ORDER BY DESC(?children)
LIMIT 50

Try it!

French heads of government by length of service

SELECT DISTINCT ?item ?itemLabel ?positionLabel ?picture ?start ?end ?days WHERE
{
  ?item wdt:P31 wd:Q5 ;
        p:P39 ?position_statement .
  ?position_statement ps:P39 ?position ;
                      pq:P580 ?start FILTER (?start >= "1815-01-01T00:00:00Z"^^xsd:dateTime) .
  ?position wdt:P279* wd:Q15135541 .
  OPTIONAL { ?position_statement pq:P582 ?x }
  OPTIONAL { ?item wdt:P18 ?picture }
  bind(if(bound(?x), ?x, NOW()) as ?end )
  bind(floor(?end - ?start) as ?days)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}
ORDER BY DESC(?days) ?itemLabel

Try it!

List of countries in 1754

#added before 2016-10
SELECT ?h ?hLabel ?inception ?dissolved ?coor
WHERE
{
	VALUES ?countryclass { wd:Q3024240 wd:Q6256 }
  	?h wdt:P31 ?countryclass  .
	?h wdt:P571 ?inception .
	OPTIONAL { ?h wdt:P576 ?dissolved } .
	FILTER (?inception < "1755-01-01T00:00:00Z"^^xsd:dateTime)
	FILTER (?dissolved >= "1755-01-01T00:00:00Z"^^xsd:dateTime || !Bound(?dissolved) )
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
	OPTIONAL { ?h wdt:P625 ?coor } .
}
ORDER BY ?inception

Try it!

Population in Europe after 1960

#added before 2016-10

SELECT  ?objectLabel    (YEAR(?date) as ?year)
        ?population     (?objectLabel as ?Location)
WHERE
{
        wd:Q458 wdt:P150 ?object .   # European Union  contains administrative territorial entity
        ?object p:P1082 ?populationStatement .
        ?populationStatement    ps:P1082 ?population
        ;	pq:P585 ?date .
        SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }               
	FILTER (YEAR(?date) >= 1960)
}
ORDER BY ?objectLabel ?year

Try it!

Locations of air accidents

#added before 2016-10
 SELECT ?label ?coord ?place
WHERE
{
   ?subj wdt:P31 wd:Q744913  .
   ?subj wdt:P625 ?coord .
   ?subj rdfs:label ?label filter (lang(?label) = "en")
}

Try it!

Most prolific fathers

#added before 2016-10
 SELECT  (SAMPLE(?father) as ?father) ?fatherLabel  (SAMPLE(?picture) as ?picture) (COUNT(?father) as ?children)
WHERE
{
	?subj wdt:P22 ?father .
	OPTIONAL {
		?father wdt:P18 ?picture .
		}
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
GROUP BY ?fatherLabel
ORDER BY DESC(?children)
LIMIT 50

Try it!

List of suicide attacks

#added before 2016-10

SELECT ?h ?hLabel ?location (CONCAT("injured: ",str(?injured)) as ?injuredl) (concat("dead: ",str(?dead)) as ?deadl) ?date ?image
WHERE
{
        ?h wdt:P31 ?attack. 
    values (?attack) {
      (wd:Q18493502)
      (wd:Q217327)
     
     
    }
    optional {    ?h wdt:P1339 ?injured . }
    optional {    ?h wdt:P1120 ?dead. }
    optional {    ?h wdt:P276?/wdt:P625 ?location }
    optional {    ?h wdt:P585 ?date }
    optional {    ?h wdt:P18 ?image }
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}

Try it!

People who died by burning - on a timeline

#added before 2016-10

#defaultView:Timeline
SELECT ?person ?personLabel ?date
WHERE
{
  ?person wdt:P31 wd:Q5;
          wdt:P509 wd:Q468455;
          wdt:P570 ?date.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?date

Try it!

People who lived in the same period as another person

#added before 2016-10

select ?person ?personLabel ?personDescription ?birth ?death ?age
WHERE
{
  ?person wdt:P31 wd:Q5. # instance of human
  ?person wdt:P569 ?birth . # birth date
  ?person wdt:P570 ?death . # death date
  bind( year(?death)-year(?birth) as ?age ) # Make a new variable called ?age that we can use
  filter (?age > 10 && ?age < 100) # Only find people with realistic ages 
  filter (?birth > "1452-04-15"^^xsd:dateTime && ?death < "1519-05-02"^^xsd:dateTime) # And between these two dates
  service wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # used to display a label
}

Try it!

People elevated in the public domain in 2020 "life+50 years"

#added before 2019-02

#Shows people raised in the public domain "life + 50 years".
SELECT ?item ?itemLabel ?genderLabel (GROUP_CONCAT(DISTINCT ?occupationLabel; SEPARATOR=", ") AS ?occupations) (GROUP_CONCAT(DISTINCT ?countryLabel; SEPARATOR=", ") AS ?countries) ?death ?articles {
  VALUES ?target_country { wd:Q16 wd:Q142 wd:Q39 wd:Q31 wd:Q30 } . #countries: Canada, France, Switzerland, Belgium, USA. Removing this line to get worldwide may cause a query timeout.
  VALUES ?occ { wd:Q2500638 wd:Q20826540 wd:Q215627 } . #occupation: creator, erudite, person. These 3 occupations will also look for subclasses. Example: Alan Turing is a cryptographer, a subclass of cryptologist, a subclass of mathematician, a subclass of scientist, a subclass of erudite.
   ?item wdt:P31 wd:Q5;
               wdt:P21 ?gender;
               wdt:P27 ?target_country;
               wdt:P27 ?country;
               wdt:P106/wdt:P279* ?occ ;
               wdt:P106 ?occupation;
               wikibase:sitelinks ?articles . #Service to count the number of articles in Wikipedia language versions. The higher the number, the greater the chances that the person is very notorious.
   ?item wdt:P570 ?death . hint:Prior hint:rangeSafe true .
   FILTER( ?death >= "1969-01-01T00:00:00"^^xsd:dateTime && ?death < "1970-01-01T00:00:00"^^xsd:dateTime ) #death: public domain "life+50 years". Change both years to get a list in different legislation. Example for USA: life+70 years
   SERVICE wikibase:label {
       bd:serviceParam wikibase:language "fr,en" . #Service to retrieve the labels of items, in order of language. Example: if the label does not exist in French, the service will take the English label
       ?item rdfs:label ?itemLabel .
       ?gender rdfs:label ?genderLabel .
       ?occupation rdfs:label ?occupationLabel .
       ?country rdfs:label ?countryLabel .
   } .
} GROUP BY ?item ?itemLabel ?genderLabel ?death ?articles ORDER BY DESC (?articles) #Order by the number of articles in Wikipedia language versions. The most notorious people will be at the top of the list.

Try it!

List of torture devices

#added before 2016-10
 SELECT ?thing ?thingLabel ?image
WHERE
{
  ?thing wdt:P366 wd:Q132781 .
  ?thing wdt:P18 ?image .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}

Try it!

Animals that were executed

#added before 2016-10

SELECT ?animal ?animalLabel ?died ?mannerOfDeathLabel ?image
WHERE
{
  ?animal wdt:P31/wdt:P31 wd:Q16521; # instance of some taxon (does not include human)
          wdt:P509 ?mannerOfDeath.
  ?mannerOfDeath wdt:P279* wd:Q8454. # some subclass of capital punishment
  OPTIONAL { ?animal wdt:P570 ?died. }
  OPTIONAL { ?animal wdt:P18 ?image. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?died

Try it!

People who were stateless for some time

# persons who were stateless (country of citizenship: no value) for some time (start time and end time qualifiers)
SELECT ?person ?personLabel ?start ?end WHERE {
  ?person wdt:P31 wd:Q5;
          p:P27 [
            rdf:type wdno:P27;
            pq:P580 ?start;
            pq:P582 ?end
          ].
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC(?end - ?start)

Try it!

Poets who were through An Lushan Rebellion

# Poets who were through An Lushan Rebellion
SELECT ?poet ?poetLabel WHERE {
 SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],zh-hant,zh". }
 wd:Q253774 wdt:P580 ?battleStartTime.
 wd:Q253774 wdt:P582 ?battleEndTime.
 ?poet wdt:P106 wd:Q49757.
 ?poet wdt:P497 ?cbdbId.
 ?poet wdt:P569 ?birthDate.
  FILTER(?birthDate < ?battleStartTime).
  ?poet wdt:P570 ?deathDate.
  FILTER(?deathDate > ?battleEndTime).
}

Try it!

Periods of Japanese history and what they were named after

SELECT ?era ?eraLabel (YEAR(?start_time) AS ?start) (YEAR(?end_time) AS ?end) ?namedLabel ?namedDescription WHERE {
?era wdt:P31 wd:Q6428674; wdt:P361 wd:Q130436; # eras of the history of Japan
  wdt:P580 ?start_time.
MINUS { ?era wdt:P2348/wdt:P361 wd:Q130436 } # exclude sub-eras
OPTIONAL { ?era wdt:P582 ?end_time } # optional end-time to make sure we include the current era
OPTIONAL { ?era wdt:P138 ?named }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
} ORDER BY ?start DESC(?end)

Try it!

Ancestors of Willem-Alexander of the Netherlands

SELECT DISTINCT ?item ?itemLabel ?dateofbirth WHERE {
  wd:Q154952 (wdt:P22|wdt:P25)* ?item .
  OPTIONAL { ?item wdt:P569 ?dateofbirth } .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
} ORDER BY ?itemLabel

Try it!

Culture

Churches

Cathedrals in Paris

#added before 2016-10

SELECT ?item ?itemLabel ?placeLabel ?coords ?image
WHERE
{
  ?item wdt:P31 wd:Q2977 .
  ?item wdt:P131 ?place .
  ?place wdt:P131 wd:Q90 .
  OPTIONAL { ?item wdt:P625 ?coords . }
  OPTIONAL { ?item wdt:P18 ?image . }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr" . }
} ORDER BY ?placeLabel ?itemLabel

Try it!

Churches in church district Wittenberg

#defaultView:Map{"layer": "?pbLabel"}
SELECT ?item ?itemLabel ?pbLabel (SAMPLE(?cat) AS ?cat) (SAMPLE(?coord) AS ?coord) (SAMPLE(?img) AS ?img)
WHERE {
  wd:Q75849591 wdt:P527 [ wdt:P527 ?item; wdt:P361 ?pb ].
  ?pb wdt:P31 wd:Q76598130.
  ?item wdt:P625 ?coord.
  OPTIONAL { ?item wdt:P373 ?cat. }
  OPTIONAL { ?item wdt:P18 ?img. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "de". }
} GROUP BY ?item ?itemLabel ?pbLabel

Try it!

Museums

Museums in Brittany

#added before 2016-10
SELECT DISTINCT ?museumLabel ?museumDescription ?villeId ?villeIdLabel (?villeIdLabel AS ?ville) ?coord ?lat ?lon
WHERE
{
  ?museum wdt:P539 ?museofile.  # french museofile Id
  ?museum wdt:P131* wd:Q12130. # in Brittany
  ?museum wdt:P131 ?villeId. #city of the museum
  # ?object wdt:P166 wd:Q2275045 # that have french label "musées de France"
  OPTIONAL {?museum wdt:P856 ?link.}     # official website
  OPTIONAL {?museum wdt:P625 ?coord .} # geographic coord
  OPTIONAL {
    ?museum p:P625 ?statement.
    ?statement psv:P625 ?node.
    ?node wikibase:geoLatitude ?lat.
    ?node wikibase:geoLongitude ?lon.
   }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". } #french label
}
ORDER BY  ?villeIdLabel

Try it!

All museums in Barcelona with coordinates

#added before 2016-10

#All museums (including subclass of museum) in Barcelona with coordinates
SELECT DISTINCT ?item ?name ?coord ?lat ?lon
WHERE
{
 hint:Query hint:optimizer "None" .
 ?item wdt:P131* wd:Q1492 .
 ?item wdt:P31/wdt:P279* wd:Q33506 .
 ?item wdt:P625 ?coord .
 ?item p:P625 ?coordinate .
 ?coordinate psv:P625 ?coordinate_node .
 ?coordinate_node wikibase:geoLatitude ?lat .
 ?coordinate_node wikibase:geoLongitude ?lon .
 SERVICE wikibase:label {
 bd:serviceParam wikibase:language "ca" .
 ?item rdfs:label ?name
 }
}
ORDER BY ASC (?name)

Try it!

Museums in Antwerp

#added before 2016-10

#defaultView:Map
SELECT ?item ?itemLabel ?coordinates
WHERE
{
  ?item wdt:P31/wdt:P279* wd:Q33506 ;
        wdt:P131 wd:Q12892 ;
        wdt:P625 ?coordinates .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "nl, en" }
  }

Try it!

Louvre artworks in display cases

#defaultView:ImageGrid
SELECT ?item ?itemLabel ?itemDescription ?image WHERE {
  #part1: objects in cases
  {
  ?item wdt:P276             ?case     .
  ?case wdt:P31            wd:Q3561331 .
  
  ?case wdt:P276             ?room     .
  ?room wdt:P31/wdt:P279*  wd:Q180516  . # wd:Q15206795
  
  ?room wdt:P466             ?dep      .
  ?dep  wdt:P361+          wd:Q19675
  }       
  
  OPTIONAL { ?item wdt:P18 ?image } # Optionally with an image

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,fr" }
}

Try it!

Performing arts

Characters portrayed by most actors

#added before 2016-10

SELECT ?character ?characterLabel (COUNT(?actor) AS ?count)
WHERE
{
  {
    SELECT DISTINCT ?character ?actor
    WHERE {
      ?film p:P161 [
        ps:P161 ?actor;
        pq:P453 ?character
      ].
      #?character wdt:P31 wd:Q5. # uncomment to filter for real people
    }
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?character ?characterLabel
ORDER BY DESC(?count)
LIMIT 25

Try it!

List of theatre plays

#added before 2016-10

SELECT ?play ?playLabel
WHERE
{
	?play wdt:P31 wd:Q25379 .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en,es,pt,de,fr,ja,zh" . }
}
LIMIT 1000

Try it!

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

#added before 2016-10

#defaultView:ImageGrid
SELECT ?human ?humanLabel ?yob ?yod ?picture
WHERE
{
	?human wdt:P31 wd:Q5
	; wdt:P106 wd:Q33999 .
	?human wdt:P18 ?picture .
	OPTIONAL { ?human wdt:P569 ?dob . ?human wdt:P570 ?dod }.
	BIND(YEAR(?dob) as ?yob) . #if available: year
	BIND(YEAR(?dod) as ?yod) .
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en" .
	}
}
LIMIT 88

Try it!

Actors who played the same role more than 40 years apart

SELECT DISTINCT ?actor ?actorLabel ?characterLabel ?movie1Label ?movie2Label WHERE {
  ?movie1 p:P161 [
            ps:P161 ?actor;
            pq:P453 ?character
          ];
          wdt:P577 ?movie1Publication.
  ?movie2  p:P161 [
            ps:P161 ?actor;
            pq:P453 ?character
          ];
          wdt:P577 ?movie2Publication.
  MINUS{?movie1 wdt:P31/wdt:P279? wd:Q24856} # Not a series
  MINUS{?movie2 wdt:P31/wdt:P279? wd:Q24856} # Not a series
  FILTER(?character != wd:Q18086706). # Not as "himself/herself"
  FILTER(?movie1Publication + "P40Y"^^xsd:duration < ?movie2Publication) # 40 years between them
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

Literature

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

#added before 2016-10
SELECT distinct ?writer ?place ?linkcount
WHERE
{
  {?s wdt:P106 wd:Q36180 .} UNION { ?s wdt:P106 wd:Q482980 . } UNION { ?s wdt:P106 wd:Q49757 . }
  ?s wdt:P27 ?pl .
  ?s wikibase:sitelinks ?linkcount .
  OPTIONAL {
     ?s rdfs:label ?writer filter (lang(?writer) = "en").
   }
    OPTIONAL {
     ?pl rdfs:label ?place filter (lang(?place) = "en").
   }
} GROUP BY ?place ?writer ?linkcount HAVING (?linkcount > 10) ORDER BY DESC(?linkcount)

Try it!

Birth places of German poets

#defaultView:Map{"hide": ["?coord"]}
SELECT ?subj ?subjLabel ?place ?placeLabel ?coord ?birthyear
WHERE {
   ?subj wdt:P106 wd:Q49757 .
   ?subj wdt:P19 ?place .
   ?place wdt:P17 wd:Q183 .
   ?place wdt:P625 ?coord .
   OPTIONAL { ?subj wdt:P569 ?dob }
   BIND(YEAR(?dob) as ?birthyear)
SERVICE wikibase:label {  bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}

Try it!

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

#added before 2016-10
SELECT ?subj ?label ?coord ?place
WHERE
{
  {?subj wdt:P31 wd:Q571 } UNION {?subj wdt:P31 wd:Q7725634}.
   ?subj wdt:P577 ?date FILTER (?date < "1830-01-01T00:00:00Z"^^xsd:dateTime) .
  OPTIONAL { {?subj wdt:P291 ?place} UNION {?subj wdt:P840 ?place }.
    ?place wdt:P625 ?coord }.
   ?subj rdfs:label ?label filter (lang(?label) = "en")
}

Try it!

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

#added before 2016-10
 SELECT ?book ?bookLabel ?authorLabel ?genre_label ?series_label ?publicationDate
WHERE
{
	?author ?label "Ernest Hemmingway"@en .
	?book wdt:P31 wd:Q571 .
	?book wdt:P50 ?author .
	OPTIONAL {
		?book wdt:P136 ?genre .
		?genre rdfs:label ?genre_label filter (lang(?genre_label) = "en").
	}
	OPTIONAL {
		?book wdt:P179 ?series .
		?series rdfs:label ?series_label filter (lang(?series_label) = "en").
	}
	OPTIONAL {
		?book wdt:P577 ?publicationDate .
	}
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en" .
	}
}

Try it!

Text by author containing case-insensitive title with optional cover image

select distinct ?item ?authorLabel ?itemLabel ?image where {
  ?item wdt:P31/wdt:P279* wd:Q234460.

  ?author ?label 'Bram Stoker'.
  ?item wdt:P50 ?author.

  ?item rdfs:label ?itemLabel.
  filter contains(lcase(?itemLabel), 'dracula').

  optional {?item wdt:P18 ?image.}

  service wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE]".}
} limit 50

Try it!

Literary works by label count

#added before 2016-10
SELECT ?s ?desc (COUNT(DISTINCT ?label) as ?labelcount)
WHERE
{
  ?s wdt:P31 wd:Q7725634 .
  ?s rdfs:label ?label .
  OPTIONAL {
     ?s rdfs:label ?desc filter (lang(?desc) = "en").
   }
 } GROUP BY ?s ?desc ORDER BY DESC(?labelcount)

Try it!

All subclasses of "Literary Work"

#added before 2016-10
SELECT ?s ?desc
WHERE
{
  ?s wdt:P279 wd:Q7725634 .
  OPTIONAL {
     ?s rdfs:label ?desc filter (lang(?desc) = "en").
   }
 }

Try it!

Epic poems by label count

#added before 2016-10
SELECT ?s ?desc (COUNT(DISTINCT ?label) as ?labelcount)
WHERE
{
  ?s wdt:P31 wd:Q37484 .
  ?s rdfs:label ?label .
  OPTIONAL {
     ?s rdfs:label ?desc filter (lang(?desc) = "en").
   }
 } GROUP BY ?s ?desc ORDER BY DESC(?labelcount)

Try it!

Epic poems by sitelink count

#added before 2016-10
#old method for sitelink count
SELECT ?s ?desc ?linkcount
WHERE
{
  ?s wdt:P31 wd:Q37484 .
  ?s wikibase:sitelinks ?linkcount .
  OPTIONAL {
     ?s rdfs:label ?desc filter (lang(?desc) = "en").
   }
 } GROUP BY ?s ?desc ?linkcount ORDER BY DESC(?linkcount)

Try it!

Instance of Book by sitelink count

#added before 2016-10
#old method for sitelink count
SELECT ?s ?desc ?linkcount
WHERE
{
  ?s wdt:P31 wd:Q571 .
  ?s wikibase:sitelinks ?linkcount .
  OPTIONAL {
     ?s rdfs:label ?desc filter (lang(?desc) = "en").
   }
 } GROUP BY ?s ?desc ?linkcount ORDER BY DESC(?linkcount)

Try it!

Poets and monarchs

#added before 2016-10

SELECT ?poetLabel ?image ?yob ?yod ?start ?end ?monarchLabel
WHERE
{
  ?poet p:P39 ?positionStat.
  ?positionStat ps:P39 wd:Q877838;
                pq:P580 ?start;
                pq:P748 ?monarch.
  OPTIONAL {
    ?positionStat pq:P582 ?end.
  }
  OPTIONAL {
    ?poet wdt:P18 ?image;
          wdt:P569 ?dob;
          wdt:P570 ?dod.
  }
  BIND(YEAR(?dob) AS ?yob).
  BIND(YEAR(?dod) AS ?yod).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?start DESC(?monarchLabel)

Try it!

List of digital libraries in the world

SELECT DISTINCT ?item ?itemLabel ?website
WHERE {
?item wdt:P31/wdt:P279* wd:Q212805   # digital libraries or subtypes
OPTIONAL { ?item wdt:P856 ?website }   # Official URL if known
MINUS { ?item wdt:P576 [] }   # Exclude those that have shut down
SERVICE wikibase:label { bd:serviceParam wikibase:language "en, es, ca, fr, de, pl, uk, ru, he" }
}
ORDER BY ?itemLabel

Try it!

Map of Libraries in Canada

# Canadian libraries on a map (must have coordinates!)
#defaultView:Map
SELECT ?library ?libraryLabel ?coords WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,fr". }
  ?library (wdt:P31/wdt:P279*) wd:Q7075.
  ?library wdt:P17 wd:Q16.
  ?library wdt:P625 ?coords.
}
LIMIT 100

Try it!

List of authors unsuccessfully nominated for Nobel prize in literature

SELECT ?nominee ?nomineeLabel (SAMPLE(?citizenshipLabel) AS ?country) (COUNT(DISTINCT ?year) as ?timesNominated)
WHERE
{
    BIND( wd:Q37922 as ?prize )
    ?nominee p:P1411 [ ps:P1411 ?prize; pq:P585 ?time ]
    BIND( year(?time) as ?year )                   
    OPTIONAL { 
      ?nominee wdt:P27 [ rdfs:label ?citizenshipLabel ] filter (lang(?citizenshipLabel) = "en") .
    }
    FILTER NOT EXISTS { ?nominee wdt:P166 ?prize . } 
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?nominee ?nomineeLabel
ORDER BY DESC(?timesNominated) ?nomineeLabel

Try it!

Authors whose works enter the public domain in 2017 (died in 1946)

SELECT DISTINCT ?item WHERE
{
  ?item wdt:P31 wd:Q5 ;
  wdt:P106/wdt:P279* wd:Q482980 .
  ?item wdt:P570 ?time0 .
  FILTER((?time0 >= "1945-01-01T00:00:00Z"^^xsd:dateTime) && (?time0 <= "1946-01-01T00:00:00Z"^^xsd:dateTime))
}

Try it!

All events that occured on 2001/09/11

SELECT ?item ?itemLabel 
WHERE
{
  ?item  p:P585/ps:P585 "2001-09-11T00:00:00Z"^^xsd:dateTime
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

Works by women that were born between 1800 and 1900, are in the WomenWriters database and are translated

select ?translator ?translatorLabel ?work ?workLabel ?author ?authorLabel {  
    ?work wdt:P655 ?translator;        
          wdt:P50 ?author.    

    ?author wdt:P2533 ?wid;          
            wdt:P21 wd:Q6581072;          
            wdt:P569 ?birth;            

    filter (?birth > "1800-01-01"^^xsd:dateTime && ?birth < "1900-01-01"^^xsd:dateTime)

    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,nl,fr". }
}

Try it!

Music

Timeline of albums by Manu Chao and Mano Negra

#defaultView:Timeline
SELECT ?album ?performerLabel ?albumLabel ?publication_date WHERE {
  VALUES ?performer {
      wd:Q936474
      wd:Q207898
    }
   ?album wdt:P175 ?performer ;
      wdt:P577 ?publication_date .
   SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

Most popular tonality

#added before 2016-10
 SELECT ?tonalityLabel (COUNT(?tonalityLabel) as ?count)
WHERE
{
  ?work wdt:P826 ?tonality.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?tonalityLabel
ORDER BY DESC(?count)

Try it!

Music composers by birth place

#defaultView:Map
SELECT ?item ?itemLabel ?_coordinates ?_image WHERE {
  ?item wdt:P106 wd:Q36834;   # occupation: composer
        wdt:P18 ?_image;   # with an image depicting them
        wdt:P19/wdt:P625 ?_coordinates   # their birthplace, specifically the coordinates of their birthplace
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }  # labels in English
}

Try it!

Composers and their most-used tonality

#added before 2016-10

# Each composer’s most used tonality, with number of works in that tonality.
# (If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)
#
# The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).
# To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count
WHERE
{
  {
    # 4. Group again, this time just by the composer.
    #    We also select the highest count of a tonality.
    #    Notice that we don’t know what tonality this count is associated with – we’ll get to that.
    #    So now we have each composer, along with how often they used whatever tonality they used most.
    SELECT ?composer (MAX(?count) AS ?count)
    WHERE
    {
      {
        # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality.
        SELECT ?composer ?tonality (COUNT(?composition) AS ?count)
        WHERE
        {
          # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality.
          #    (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.)
          ?composition wdt:P86 ?composer;
                       wdt:P826 ?tonality.
        }
        GROUP BY ?composer ?tonality
        HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”.
      }
    }
    GROUP BY ?composer
  }
  {
    # 6. Identical to 2.
    SELECT ?composer ?tonality (COUNT(?composition) AS ?count)
    WHERE
    {
      # 5. Identical to 1.
      ?composition wdt:P86 ?composer;
                   wdt:P826 ?tonality.
    }
    GROUP BY ?composer ?tonality
    HAVING(?count > 1) # 7. Identical to 3.
  }
  # 8. That’s it. Wait, what?
  #    From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most.
  #    From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality.
  #    The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined,
  #    we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 –
  #    that is, where this tonality was used as often as the composer’s most-used tonality.
  #    In other words, this must *be* the composer’s most-used tonality (except when there are multiple tonalities with the same count).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement).

Try it!

Songs with longest melody

#added before 2016-10

SELECT ?song ?songLabel ?code
WHERE
{
  ?song wdt:P1236 ?code.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(STRLEN(REPLACE(?code, " ", "")))
LIMIT 10

Try it!

How many musicians dies at certain age

#added before 2016-10

   # Query to find all musicians who have already died
   # calculate their age (full years) at death
   # count how many of them died at each age

    SELECT ?age  (COUNT (DISTINCT ?a) AS ?count) WHERE {
        ?a wdt:P31 wd:Q5 . #instance of human
        ?a wdt:P106/wdt:P279 wd:Q639669 . #occupation a subclass of musician
        ?a p:P569/psv:P569 ?birth_date_node .
        ?a p:P570/psv:P570 ?death_date_node .
        ?birth_date_node wikibase:timeValue ?birth_date .
        ?death_date_node wikibase:timeValue ?death_date .
        FILTER(?age > 10 && ?age < 100) . #ignore outlyers, several of which are probably errors
        BIND( year(?death_date) - year(?birth_date) - if(month(?death_date)<month(?birth_date) || (month(?death_date)=month(?birth_date) && day(?death_date)<day(?birth_date)),1,0) as ?age )
        # calculate the age, precisely to the day (times and timezones ignored)
    }
	GROUP BY ?age
    ORDER BY ?age

Try it!

Musicians born in Rotterdam (the Netherlands)

select distinct ?item ?itemLabel ?itemDescription where {
    ?item wdt:P106/wdt:P279* wd:Q639669 .
    ?item wdt:P19 wd:Q34370 .
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en,nl" }
}

Try it!

Paintings depicting woodwind instruments

Paintings depicting woodwind instruments
# added in 2017-06
#defaultView:ImageGrid
SELECT ?item ?itemLabel ?object ?objectLabel ?image
WHERE
{
  ?item wdt:P31/wdt:P279* wd:Q3305213 .  
  ?item wdt:P180 ?object .
  ?object wdt:P279* wd:Q181247 . 
  ?item wdt:P18 ?image .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

Paintings depicting musical instruments with some connection to Hamburg

#defaultView:ImageGrid
SELECT DISTINCT ?item ?image {
  hint:Query hint:optimizer "None" .
  ?object wdt:P279* wd:Q34379 .
  ?item wdt:P180 ?object .
  ?item wdt:P31/wdt:P279* wd:Q3305213 .  
  ?item wdt:P18 ?image .
  ?item ?prop ?hhlink .
  ?hhlink ?prop2 wd:Q1055 . 
}

Try it!

Visual arts

Public sculptures in Paris

#added before 2016-10
 SELECT DISTINCT ?item  ?Titre ?createur (year(?date) as ?AnneeCreation) ?image ?coord
WHERE
{
   ?item wdt:P31/wdt:P279* wd:Q860861.                    # sculpture
   ?item wdt:P136 wd:Q557141 .                            # genre : art public
   {?item wdt:P131 wd:Q90.}                               # ... située dans Paris
   UNION
   {?item wdt:P131 ?arr.                                  # ... ou dans un arrondissement de Paris 
   ?arr wdt:P131 wd:Q90. }
   ?item rdfs:label ?Titre filter (lang(?Titre) = "fr").  # Titre
 
   OPTIONAL {?item wdt:P170 ?Qcreateur.                   # créateur/créatrice (option)
   ?Qcreateur rdfs:label ?createur filter (lang(?createur) = "fr") .}
   OPTIONAL {?item wdt:P571 ?date.}                       # date de création (option)
   OPTIONAL {?item wdt:P18  ?image.}                      # image (option)
   OPTIONAL {?item wdt:P625 ?coord.}                      # coordonnées géographiques (option)
}

Try it!

Locations of Pablo Picasso works

#added before 2016-10

#defaultView:Map
SELECT ?label ?coord ?subj
WHERE
{
   ?subj wdt:P170 wd:Q5593 .
  OPTIONAL {?subj wdt:P276 ?loc .
    ?loc wdt:P625 ?coord } .   
   ?subj rdfs:label ?label filter (lang(?label) = "en")
}

Try it!

Eiffel Tower in art

#added before 2016-10
SELECT DISTINCT ?item ?itemLabel ?instanceLabel ?creatorLabel (YEAR(?date) as ?year) ?image
WHERE
{
  ?item wdt:P180 wd:Q243 .
  ?item wdt:P31 ?instance .
  OPTIONAL { ?item wdt:P170 ?creator }
  OPTIONAL { ?item wdt:P571 ?date }
  OPTIONAL { ?item wdt:P18 ?image }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
ORDER BY ?itemLabel

Try it!

Paintings by Gustav Klimt

#added before 2016-10
#defaultView:ImageGrid
SELECT *
WHERE
{
  ?item wdt:P31 wd:Q3305213 .
  ?item wdt:P170 wd:Q34661 .
  ?item wdt:P18 ?pic .
}

Try it!

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

#added before 2016-10

#Map of all the paintings for which we know a location with the count per location
#defaultView:Map
SELECT ?locationLabel ?coord (count(*) as ?count)
WHERE
{
    ?painting wdt:P31 wd:Q3305213 .
    ?painting wdt:P276 ?location .
	?location wdt:P625 ?coord
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }      
}
GROUP BY ?locationLabel ?coord

Try it!

Versions of The Scream

#added before 2016-10

SELECT
  ?item
  (SAMPLE (?itemL) AS ?title)
  (SAMPLE (?y) AS ?year)
  (SAMPLE (?typeL) AS ?type)
  (group_concat(distinct ?materialL ; separator = ", ") as ?materials)
  (SAMPLE (?collectionL) AS ?collection)
  (SAMPLE (?img) AS ?image)
{
  SELECT ?item ?itemL (YEAR(?date) AS ?y) ?typeL ?collectionL ?img ?materialL
  WHERE {
    ?item wdt:P179 wd:Q471379 .
    ?item wdt:P18 ?img .
    ?item wdt:P571 ?date .
    ?item wdt:P31 ?instance .
    ?item rdfs:label ?itemL filter (lang(?itemL) = "en").
    ?instance rdfs:label ?typeL filter (lang(?typeL) = "en").
    OPTIONAL {
      ?item wdt:P195 ?collection .
      ?collection rdfs:label ?collectionL filter (lang(?collectionL) = "en").
    }
    OPTIONAL {
      ?item wdt:P186 ?material .
      ?material rdfs:label ?materialL filter (lang(?materialL) = "en").
    }
  }
}
GROUP BY ?item
ORDER BY ?year ?item ?itemLabel

Try it!

Depicted objects in art work

#added before 2016-10

SELECT DISTINCT ?depicts (SAMPLE(?dL) AS ?depictsLabel) (COUNT(DISTINCT ?item) AS ?count)
WHERE
{
	?item wdt:P180 ?depicts .
	OPTIONAL { ?depicts rdfs:label ?dL	filter (lang(?dL) = "en")  }
}
GROUP BY ?depicts
ORDER BY DESC(?count) ?depictsLabel

Try it!

Monuments historiques in Loire-Atlantique

#added before 2016-10

SELECT DISTINCT
  ?item
  ?itemLabel
  ?communeLabel
  (group_concat(distinct ?merimee ; separator = ", ") as ?merimee)
  ?coords
  ?image
WHERE
{
  {
    SELECT DISTINCT ?item ?merimee WHERE {
      ?item wdt:P1435/wdt:P279* wd:Q916475 .
      ?item p:P1435 ?heritage_statement .
      FILTER NOT EXISTS { ?heritage_statement pq:P582 ?end . }
      ?item wdt:P380 ?merimee.
    }
    ORDER BY ?merimee
  }
  ?item wdt:P131/wdt:P131* wd:Q3068 .
  ?item wdt:P131 ?commune .
  OPTIONAL { ?item wdt:P625 ?coords . }
  OPTIONAL { ?item wdt:P18 ?image . }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr" . }
}
GROUP BY ?item ?itemLabel ?communeLabel ?coords ?image
ORDER BY ?communeLabel ?itemLabel

Try it!

Sculptures by Max Bill

#added before 2016-10

SELECT DISTINCT ?item ?itemLabel ?countryLabel ?placeLabel (YEAR(?date) as ?year) ?coords ?image
WHERE
{
  ?item wdt:P31/wdt:P279* wd:Q860861 .
  ?item wdt:P170 wd:Q123454 .
  OPTIONAL { ?item wdt:P17 ?country . }
  OPTIONAL { ?item wdt:P131 ?place . }
  OPTIONAL { ?item wdt:P571 ?date . }
  OPTIONAL { ?item wdt:P625 ?coords . }
  OPTIONAL { ?item wdt:P18 ?image . }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
ORDER BY ?itemLabel ?placeLabel

Try it!

Paintings by Rembrandt in the Louvre or the Rijkmuseum

#defaultView:ImageGrid

SELECT DISTINCT ?item ?itemLabel ?itemDescription ?image ?collection WHERE {
    ?item wdt:P31 wd:Q3305213 ; # Get items that are instances of painting
          wdt:P170 wd:Q5598 ; # By creator Rembrandt
          wdt:P195/wdt:P361* ?collection . # That are in some collection

    # Only return results where 'collection' is either Rijkmuseum or Louvre
    FILTER ( ?collection = wd:Q190804 || ?collection = wd:Q19675 )
 
    OPTIONAL { ?item wdt:P18 ?image } # Optionally with an image

    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]" }
}

Try it!

Authority control properties usage for paintings

# Make a list of the most used authority control properties for works for paintings
SELECT ?propertyLabel ?propertyDescription (COUNT(?propertyclaim) AS ?count) WHERE {
  ?item wdt:P31 wd:Q3305213 .

  ?property wikibase:propertyType wikibase:ExternalId .
  ?property wdt:P31 wd:Q44847669 .
  ?property wikibase:claim ?propertyclaim .

  ?item ?propertyclaim [] .
	SERVICE wikibase:label {            # ... include the labels
		bd:serviceParam wikibase:language "en" .
	}  
} GROUP BY ?propertyLabel ?propertyDescription ORDER BY DESC (?count)
LIMIT 100

Try it!

Authority control properties usage for painters

# Make a list of the most used authority control properties for people for painters
SELECT ?propertyLabel ?propertyDescription ?count WHERE {
	{
		select ?propertyclaim (COUNT(*) AS ?count) where {
			?item wdt:P106 wd:Q1028181 .
			?item wdt:P31 wd:Q5 .
			?item ?propertyclaim [] .
		} group by ?propertyclaim
	}
	?property wikibase:propertyType wikibase:ExternalId .
	?property wdt:P31 wd:Q19595382 .
	?property wikibase:claim ?propertyclaim .
	SERVICE wikibase:label {            # ... include the labels
		bd:serviceParam wikibase:language "en" .
	}
} ORDER BY DESC (?count)
LIMIT 100

Try it!

Ten random painting images

# This returns 10 random painting images
# RAND() returns one random number (cached like every query).
# The string representation of the item and the random number are hashed.
# This will give a complete different ordering every time you have a different random number.
# You can change the LIMIT if you want to trigger a new random number
#defaultView:ImageGrid
SELECT ?item ?itemLabel ?image (MD5(CONCAT(str(?item),str(RAND()))) as ?random)  WHERE {
  ?item wdt:P31 wd:Q3305213.
  ?item wdt:P18 ?image.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en"}
} ORDER BY ?random
LIMIT 10

Try it!

Painters related to anonymous works

#Paintings by anonymous painters, but are related to some other painter
#defaultView:BubbleChart
SELECT ?creatorqualifierLabel (COUNT(?creatorqualifier) AS ?count) WHERE {
  ?item wdt:P31 wd:Q3305213 .
  ?item wdt:P170 wd:Q4233718 .
  OPTIONAL { ?item p:P170 ?creatorstatement .
             ?creatorstatement rdf:type	wikibase:BestRank .
             ?creatorstatement ?qualifier ?creatorqualifier .
             ?qualifierproperty wikibase:qualifier ?qualifier }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }         
  } GROUP BY ?creatorqualifierLabel
HAVING (?count > 2)
LIMIT 20000

Try it!

Painters type of relations with anonymous works

#Paintings by anonymous painters, types of relationships with other painters
#defaultView:BubbleChart
SELECT ?qualifierpropertyLabel (COUNT(?creatorqualifier) AS ?count) WHERE {
  ?item wdt:P31 wd:Q3305213 .
  ?item wdt:P170 wd:Q4233718 .
  OPTIONAL { ?item p:P170 ?creatorstatement .
             ?creatorstatement rdf:type	wikibase:BestRank .
             ?creatorstatement ?qualifier ?creatorqualifier .
             ?qualifierproperty wikibase:qualifier ?qualifier }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }         
  } GROUP BY ?qualifierpropertyLabel
HAVING (?count > 2)
LIMIT 2000

Try it!

Using formatter url to construct links in SPARQL

# Get 10 paintings that have a link to RKDimages (P350)
# Use the formatter URL (P1630) to construct the links to RKDimages
#defaultView:ImageGrid
SELECT ?item ?image ?rkdurl  WHERE {
  wd:P350 wdt:P1630 ?formatterurl .
  ?item wdt:P31 wd:Q3305213 .
  ?item wdt:P18 ?image .
  ?item wdt:P350 ?rkdid .
  BIND(IRI(REPLACE(?rkdid, '^(.+)$', ?formatterurl)) AS ?rkdurl).
  } LIMIT 10

Try it!

Map of the locations of all paintings by Johannes Vermeer with an image

#defaultView:Map
select ?painting ?paintingLabel ?location ?image where {
  ?painting wdt:P276 ?collection;
            wdt:P170 wd:Q41264;
            wdt:P18 ?image.
  ?collection wdt:P625 ?location.
  service wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

Public art in Paris

#added before 2016-10

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)
WHERE
{
  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)
    }

Try it!

Works of art where the name might be a rhyme

#added before 2016-10
SELECT ?work ?title
WHERE
{
  ?work wdt:P31/wdt:P279* wd:Q838948;
        wdt:P1476 ?title.
  FILTER(REGEX(?title, "^\\w*(\\w{3})(\\W+\\w*\\1)+$", "i") && !REGEX(?title, "^(\\w+)(\\W+\\1)+$", "i")).
}
ORDER BY STR(?title)

Try it!

Works of art where the title is an alliteration

#added before 2016-10
SELECT ?work ?title
WHERE
{
  ?work wdt:P31/wdt:P279* wd:Q838948;
        wdt:P1476 ?title.
  FILTER(REGEX(STR(?title), "^(\\p{L})\\w+(?:\\W+\\1\\w+){2,}$", "i")).
}
ORDER BY STR(?title)

Try it!

Distribution of public art by place

#added before 2016-10

SELECT ?place ?placeLabel (COUNT(*) AS ?count) WHERE {
  ?item wdt:P136 wd:Q557141 .
  ?item wdt:P131 ?place .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
GROUP BY ?place ?placeLabel
ORDER BY DESC(?count) ?placeLabel

Try it!

Birthplaces of Europeana280 artists

#added before 2016-10

#defaultView:Map
SELECT ?creator ?creatorLabel ?placebirthLabel ?geoloc where {
  ?item wdt:P31/wdt:P279* wd:Q838948 .  # œuvre d’art et ss-classe
  ?item wdt:P608 wd:Q20980830 . # du projet Europeana 280
  ?item wdt:P170 ?creator . # créateur
  ?creator wdt:P19 ?placebirth . # lieu de naissance
  ?placebirth wdt:P625 ?geoloc . #coordonnées géo
  SERVICE wikibase:label {
       bd:serviceParam wikibase:language "fr,es,en" .
    } 
}

Try it!

Female artists

#added before 2016-10

SELECT DISTINCT ?women ?womenLabel
WHERE
{
       ?women wdt:P31 wd:Q5 .
       ?women wdt:P21 wd:Q6581072 .
       ?women wdt:P106/wdt:P279* wd:Q483501 . # artists
       SERVICE wikibase:label {bd:serviceParam wikibase:language "fr,en" }
}
LIMIT 500

Try it!

Common phrases

#added before 2016-10

SELECT ?q ?qLabel
WHERE
{
	?q wdt:P31 wd:Q15841920.
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

Food & Drink

German breweries

#added before 2016-10
#Locations of breweries in Germany
#defaultView:Map
select ?breweryLabel ?breweryDescription ?coord
WHERE
{
	?brewery wdt:P31/wdt:P279* wd:Q131734 ;
		wdt:P17 wd:Q183 ;
		wdt:P625 ?coord .
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en, de" .
	}
}

Try it!

Sandwiches

#added before 2016-10

#defaultView:ImageGrid
SELECT ?item ?itemLabel ?_image
WHERE
{
  ?item wdt:P279 wd:Q28803.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
OPTIONAL { ?item wdt:P18 ?_image. }
}
LIMIT 100

Try it!

Sandwich ingredients

#added before 2016-10
SELECT ?sandwich ?ingredient ?sandwichLabel ?ingredientLabel
WHERE
{
  ?sandwich wdt:P31?/wdt:P279* wd:Q28803;
            wdt:P527 ?ingredient.
  MINUS { ?ingredient wdt:P279* wd:Q7802. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en", "fr". }
}
ORDER BY UCASE(STR(?sandwichLabel))

Try it!

Sports

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

#added before 2016-10
SELECT distinct ?race ?raceLabel ?musherLabel
WHERE
{
	{ ?race wdt:P31/wdt:P279* wd:Q1968664 . }
	UNION { ?race wdt:P31/wdt:P641* wd:Q1968664 . }
	?race p:P710 ?musherS . 	#here we have a full statement, not a value
	?musherS ps:P710 ?musher . 	#here we get the value
	FILTER NOT EXISTS { ?musherS pq:P1352 ?rank }
	FILTER NOT EXISTS { ?musherS pq:P793 ?event }
	SERVICE wikibase:label { bd:serviceParam wikibase:language "fr,en" }
}
ORDER BY ?raceLabel

Try it!

What is the relation between Terrell Buckley and Miami Dolphins?

#added before 2016-10
SELECT ?l
WHERE {
	wd:Q5571382 ?p wd:Q223243 .
	?property ?ref ?p .
	?property rdf:type wikibase:Property .
	?property rdfs:label ?l FILTER (lang(?l) = "en")
}

Try it!

The awards received by Cristiano Ronaldo by year

Shows only the year instead of the default format (i.e. show all of the date information).

SELECT ?entity ?desc (year(?date) as ?year) {
  wd:Q11571 p:P166 [ps:P166 ?entity ; pq:P585 ?date ]
  OPTIONAL { ?entity rdfs:label ?desc FILTER((LANG(?desc)) = "en") }
} ORDER BY ?year

Try it!

Women

Women mushers

select distinct ?musher ?musherLabel
where {
    ?musher wdt:P31 wd:Q5 .
    ?musher wdt:P106 wd:Q500097 .
    ?musher wdt:P21 wd:Q6581072
    service wikibase:label { bd:serviceParam wikibase:language "fr,en" . }
}

Try it!

Female brewer

SELECT ?item ?itemLabel ?itemDescription WHERE {
  ?item wdt:P31 wd:Q5
  ; wdt:P21 wd:Q6581072
  ; wdt:P106 wd:Q836904.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?itemLabel

Try it!

Female scientists

# Female scientists

SELECT ?item ?itemLabel ?lastnameLabel ?birthdate ?deathdate ?nationalityLabel ?itemDescription WHERE {
    ?item wdt:P31 wd:Q5 .
    ?item wdt:P21 wd:Q6581072 .
    ?item wdt:P106/wdt:P279* wd:Q901 .
    optional { ?item wdt:P734 ?lastname . }
    optional { ?item wdt:P569 ?birthdate . }
    optional { ?item wdt:P570 ?deathdate . }
    optional { ?item wdt:P27 ?nationality . }

  SERVICE wikibase:label { bd:serviceParam wikibase:language "nl,en,fr,de,es,it,no" }
}

order by ?itemLabel

Try it!

Verify women descriptions

SELECT ?item ?itemLabel ?occupationLabel ?itemDescription WHERE {
  ?item wdt:P31 wd:Q5.
  ?item wdt:P21 wd:Q6581072.
  ?item wdt:P27 wd:Q31.
  optional{ ?item wdt:P106 ?occupation. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "nl". }
}

Try it!

If needed you can update inappropriate descriptions.

Tips:

Streets in France named after a woman

SELECT ?street ?streetLabel ?cityLabel ?namedLabel
WHERE
{
    ?street wdt:P31 wd:Q79007 .
    ?street wdt:P17 wd:Q142 .
    ?street wdt:P131 ?city .
    ?street wdt:P138 ?named .
    ?named wdt:P21 wd:Q6581072
    SERVICE wikibase:label { bd:serviceParam wikibase:language "fr" }
}
ORDER BY ?city

Try it!

Queries for bibliographic citation (Wikicite)

Figshare citations

Wikidata statements with a reference to data in Figshare

SELECT ?doi (count(?doi) as ?counts) WHERE {
   ?statement prov:wasDerivedFrom ?ref . 
   ?ref pr:P356 ?doi .
   FILTER (CONTAINS(lcase(?doi), "figshare"))   
}
GROUP BY ?doi
ORDER BY DESC(?counts)

Try it!

Wikidata statement with a reference to data in Figshare of which a Wikicite item exists

SELECT DISTINCT ?wikiciteLabel ?doi  WHERE {
   ?wikicite p:P356/ps:P356 ?doi .
   ?statement prov:wasDerivedFrom ?ref . 
   ?ref pr:P356 ?doi .
   FILTER (CONTAINS(lcase(?doi), "figshare")) 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

Wikidata statements with a reference to a Figshare DOI (Q28061352)

SELECT DISTiNCT ?item ?itemLabel WHERE {
   ?item ?p ?statement.
   ?statement prov:wasDerivedFrom ?ref . 
   ?ref ?prop wd:Q28061352 .
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

Zika corpus

Scholarly articles with "Zika" in the item label

The following query uses these:

  • Properties: instance of (P31)  , PubMed ID (P698)  
    1 SELECT DISTINCT ?item ?itemLabel ?_PubMed_ID
    2 WHERE
    3 {
    4   ?item wdt:P31 wd:Q13442814 ;
    5         rdfs:label ?itemLabel .
    6   OPTIONAL { ?item wdt:P698 ?_PubMed_ID. }
    7   FILTER(CONTAINS(LCASE(?itemLabel), "zika"))
    8   FILTER (LANG(?itemLabel)="en")
    9 }
    
Try it!

Most common Zika author

SELECT ?short_author ?short_authorLabel (count(?item) as ?count)
WHERE
{
  { ?item wdt:P921 wd:Q202864 . } UNION { ?item wdt:P921 wd:Q8071861 . }
  {?item wdt:P2093 ?short_author .} UNION {?item wdt:P50 ?short_author .}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?short_author ?short_authorLabel
ORDER BY DESC(?count)

Try it!

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

#added before 2016-10
SELECT ?item ?itemLabel ?reference  ?referenceType
WHERE
{
  ?item wdt:P31 wd:Q13442814 #Scientific article
  { ?item wdt:P921 wd:Q202864 } #Zika virus
  UNION
  { ?item wdt:P921 wd:Q8071861 } #Zika fever
  ?reference ?referenceType ?item  #find references to item having any property and store reference type
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

CIViC Corpus

Get the CIViC citation corpus

SELECT DISTINCT ?pmid ?citation ?citationLabel
WHERE
{
	VALUES ?predictor {p:P3354 p:P3355 p:P3356 p:P3357 p:P3358 p:P3359 }
    ?item p:P3329 ?civicId  ;     
          ?predictor ?predictor_value .
    ?civicId ps:P3329 ?id .
    ?predictor_value prov:wasDerivedFrom ?reference .
    ?reference pr:P248 ?citation . 
    ?citation wdt:P698 ?pmid ;
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

Biological pathway citation corpora

Get the Pathways citation corpus

SELECT ?id ?item ?itemLabel ?referenceLabel
WHERE
{
	{?item wdt:P3937 ?id } UNION
        {?item wdt:P2410 ?id }
        ?item wdt:P2860 ?reference .
   
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

Get the Wikipathways citation corpus

SELECT ?wpid ?item ?itemLabel ?referenceLabel
WHERE
{
	?item wdt:P2410 ?wpid ;
          wdt:P2860 ?reference ;
   
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

Get the Reactome citation corups

SELECT ?reactome_id ?item ?itemLabel ?referenceLabel
WHERE
{
	?item wdt:P3937  ?reactome_id ;
          wdt:P2860 ?reference ;
   
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

Suriname citation corpora

SELECT ?item ?itemLabel ?_PubMed_ID
WHERE
{
  ?item wdt:P31 wd:Q13442814 ;
        rdfs:label ?itemLabel .
 
  FILTER(CONTAINS(LCASE(?itemLabel), "suriname"))
  OPTIONAL { ?item wdt:P698 ?_PubMed_ID. }
}

Try it!

English common names and information for animals given their scientific names

# Given the scientific name for a list of animals, it will return all the
# English common names, their length, life expectency, height, wing span and mass
# Note: There is more information on these specific animals. Unfortunately, a lot of animals on WikiData have missing information (e.g. no life expectancy or mass)
SELECT DISTINCT ?item ?scientific_name ?common_name ?length ?life_expectency ?height ?wing_span ?mass WHERE {
  ?item wdt:P225 ?scientific_name;
    wdt:P1843 ?common_name.
  OPTIONAL { ?item wdt:P2043 ?length. }
  OPTIONAL { ?item wdt:P2250 ?life_expectency. }
  OPTIONAL { ?item wdt:P2048 ?height. }
  OPTIONAL { ?item wdt:P2050 ?wing_span. }

  # Adult mass only. Excludes birth mass
  OPTIONAL {
    ?item p:P2067 ?mass_statement_node.
    ?mass_statement_node pq:P642 wd:Q78101716;
      ps:P2067 ?mass.
  }

  # Only return common names in English
  FILTER(LANGMATCHES(LANG(?common_name), "en"))

  # List of animals. All lowercase to avoid capitalisation issues
  FILTER(lcase(str(?scientific_name)) IN (
   "mustela erminea",
   "aquila adalberti",
   "vespula germanica",
   "accipiter nisus",
   "buteo buteo"
  ))
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

Retrieved from "[www.wikidata.org]" Categories:

Navigation menu

Personal tools

Namespaces

Variants

    Views

    More

      Navigation

      Print/export

      Tools

      In Wikipedia

        Add links