Shortcut: WD:RAQ

Wikidata:Request a query

From Wikidata
Jump to navigation Jump to search

Request a query
Fishing in the Wikidata river requires both an idea where to look for fish and a suitable fishing method. If you have the former, this page can help you find the latter.

This is a page where SPARQL 1.1 Query Language (Q32146616) queries can be requested. Please provide feedback if a query is written for you.

For sample queries, see Examples. Property talk pages include also summary queries for these.

For help writing your own queries, or other questions about queries, see Wikidata talk:SPARQL query service/queries.

Help resources about Wikidata Query Service (Q20950365) and SPARQL: Wikidata:SPARQL query service/Wikidata Query Help and Category:SPARQL.

On this page, old discussions are archived. An overview of all archives can be found at this page's archive index. The current archive is located at 2018/11.

Project
chat

Lexicographical
data

Administrators'
noticeboard

Development
team

Translators'
noticeboard

Request
a query

Requests
for deletions

Requests
for comment

Bot
requests

Requests
for permissions

Property
proposal

Properties
for deletion

Partnerships
and imports

Interwiki
conflicts

Bureaucrats'
noticeboard

Slide show with images[edit]

I am trying to make a slideshow with automatic looping over the a set of images returned from a WDQS query. I have made some progress on a page that loops via CCS and Javascript. I was wondering if there is a simpler way. For instance, with SAMPLE and HTML meta refresh. This will not work:

#defaultView:ImageGrid
SELECT (SAMPLE(DISTINCT ?image) AS ?image) WHERE {
  ?image ^wdt:P18 / wdt:P50 / (wdt:P108| wdt:P463 | wdt:P1416/wdt:P361*) wd:Q24283660 .
}

Try it!

 – The preceding unsigned comment was added by Fnielsen (talk • contribs) at 00:51, 21 February 2018‎ (UTC).

Country and city attribution of geolocated item[edit]

I am trying to make use of GeoData API to perform aforementioned task.

I found GeoData API very clean, simple and user friendly in retrieving various data according to geo location of the item. But there are difficulties with retrieving country/city affiliation of the item. While country can theoretically be get in a single request (also not always but only if being specified and not in name format but rather by its alphabetic designation), the city is possible to be get only for items which are cities by themselves. Let's imagine I want to determine in one request providing the coordinates of the Sagrada Familia temple the name of the item and that it is located in Barcelona, Spain. As far as I understood there is no way to do that. From the second hand this information does exist for every geo tagged item and is available for example through WikiData SPARQL query service. But then I'll need to perform a second request to WikiData which I would have liked to avoid by all means.

Looking on advice on the optimal strategy to perform the desired. If not is it possible to add the country/city attributes to GeoData list=geosearch attributes?

 – The preceding unsigned comment was added by Chainastole (talk • contribs) at 14:05, 8 September 2018 (UTC).

Possible to search to return list of items, as per website search box?[edit]

I was wondering if it is possible to use the query service to replicate the search box found on the website.

This will return results simple enough - but the ordering needs to be there.

SELECT distinct ?item ?itemLabel ?itemDescription WHERE{

 ?item ?label "Michael Jackson"@en.  
 ?article schema:about ?item .
 ?article schema:inLanguage "en" .
 ?article schema:isPartOf <https://en.wikipedia.org/>.	
 SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }    

}

 – The preceding unsigned comment was added by 185.217.68.243 (talk • contribs) at 22:20, 17 October 2018‎ (UTC).

Disambiguation with multiple value of P31[edit]

It's possible to have a query for items with multiple values of P31 and with one value of P31 = Q4167410 ? --ValterVB (talk) 14:42, 3 November 2018 (UTC)

@ValterVB:

SELECT ?item ?itemLabel ?notdab ?notdabLabel
WHERE
{
  ?item wdt:P31 wd:Q4167410 .
  ?item wdt:P31 ?notdab . FILTER( ?notdab != wd:Q4167410 )
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],it,en". }
}

Try it!

Like the above? --- Jura 15:12, 3 November 2018 (UTC)
@Jura1: Probably perfect, thanks a lot. --ValterVB (talk) 15:17, 3 November 2018 (UTC)

Replicate a list from Wikipedia[edit]

Dear all. In Wikipedia there are different list especially for economical data like inflation, gross domestic product etc. Can we for example replicate lists like this?

Maybe we could use the query here from @MisterSynergy: as a starting point.

  • Can we generate an integer showing the rank using SPARQL in one separate column for each country (attention - the european union are not ranked)?
  • Can we get (small) flaggs like in wikipedia?

Cheers! --Datawiki30 (talk) 18:50, 4 November 2018 (UTC)

@Datawiki30: We can do both those things, up to a point, and probably only in Listeria. I've constrained the report below to members of the UN security council; if we open the list to all UN members, we get a timeout. WDQS will not display flags, but were we to put this in a listeria query such that we generate a table on a wikidata / wikipedia page, we'd get the flags. So. Timeout is the main problem ... not sure what the cure there might be.
SELECT ?country ?countryLabel ?gdp ?currencyLabel ?flag (count(*) as ?rank) WHERE {
#  values ?country {wd:Q30 wd:Q184}
  ?country wdt:P463 wd:Q37470. 
  ?country2 wdt:P463 wd:Q37470.          
  ?country p:P2131 [ psv:P2131 [ wikibase:quantityAmount ?gdp; wikibase:quantityUnit ?currency ]; pq:P585 ?time; prov:wasDerivedFrom/pr:P248 wd:Q21540096 ] .
  FILTER(YEAR(?time) = 2017) .
  SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
  ?country2 p:P2131 [ psv:P2131 [ wikibase:quantityAmount ?gdp2; wikibase:quantityUnit ?currency ]; pq:P585 ?time; prov:wasDerivedFrom/pr:P248 wd:Q21540096 ] .
  filter (?gdp2 >= ?gdp)
  ?country wdt:P41 ?flag.
} group by ?country ?countryLabel ?gdp ?currencyLabel ?flag ORDER BY ?rank
Try it! --Tagishsimon (talk) 19:56, 4 November 2018 (UTC)
@Tagishsimon: Tjank you! Can we add also entities like European Union (Q458) to the list but exclude them from ranking? Do you think that we can raise the performance and avoid the timeout if we use values ?country {wd:Q30 ... } for all the coutnries? --Datawiki30 (talk) 20:30, 4 November 2018 (UTC)
@Datawiki30: Actually, thinking about it, Listeria will provide a # column, so if we put it into listeria, we can dispense with the part of the approach we're currently taking which is causing the timeout, and give you exactly what you want. Using values will not help; the problem is we, before we group things, we get one row for the #1 country, 2 rows for the #2 country, and so on ... and indeed, for 189 countries, need to fetch and do filter comparisons for ~189^2 rows ... that's hideously inefficient, though it is a shame that we don't have enough time to complete the operation. I'll try to knock up a listeria version now & ping you when done. (But I thought it would be interesting to see ranking from SPARQL in action, since it's not a game I've played before.) Not sure how we deal with the EU requirement ... might come back to that.--Tagishsimon (talk) 20:53, 4 November 2018 (UTC)
@Datawiki30: Here's the work in progress at User:Tagishsimon/junk2. If we're going to do this properly, plenty still to do, not least in making it less ugly, such as controlling the table width; making flags smaller; checking that all the GDP values are in the same currency, &c &c &c. But as a demonstrator of the principle, we're pretty much there. Rows in the table are not constrained other than that they have a GDP figure which fits the select - so the EU pops up, for instance. We could constrain by requiring the ?items to be members of the UN to get just countries; and could add in the EU by, for instance, doing a UNION with a values statement containing its QId. From here it becomes a process of working through lots of tedious checks (e.g. on currency) & trials (e.g. ensmallening flags) ... you'll have to let me know whether there's any virtue in doing that. --Tagishsimon (talk) 21:15, 4 November 2018 (UTC)
@Tagishsimon: Thank you for the fast implementation! It looks very promising. I think this is an important task and it is worth working on that to improve the list, because:
  • The data for these lists is well accessible and can stored in Wikidata
  • After the discussion here I would like to make a request to import more values to already available economic properties with the WDBot
  • This sort of lists can offer automatization for the wikipedia projects, so that editors can concentrate on other things
I know that it needs a hard work to convince the wikipedia communities. I would suggest that we make lists on some testpage in wikipedia for some properties beginning with nominal GDP (P2131). I would propose to make a test, to observe and to track the result for several months. This should help us to see if the data in Wikidata and thus the automatic gerated list are stable. I'm sure this could serve us to derive some advantages of the automatic generated lists but also to optimize the process of the list generation.
On the other side we need the actual values in the infobox of each country. For this we have (thanks to RexxS) the appropriate Lua functions - see again here.
Ready to go the next step? Cheers! --Datawiki30 (talk) 20:18, 5 November 2018 (UTC)
@Datawiki30: Maybe in 10 days or so ... feel free to ping me to remind. --Tagishsimon (talk) 00:54, 7 November 2018 (UTC)

Unexplained deprecation of ORCID iDs[edit]

Please could someone make a query for people with a ORCID iD (P496) that is deprecated, but with no reason for deprecation (P2241) qualifier? Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 15:15, 5 November 2018 (UTC)

@Pigsonthewing: Not a huge list:
SELECT ?item ?itemLabel where 
{
  ?item p:P496 ?statement.
  ?statement wikibase:rank wikibase:DeprecatedRank.
  filter not exists {?statement pq:P2241 [].}  
  SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
}
Try it! --Tagishsimon (talk) 00:52, 6 November 2018 (UTC)
@Tagishsimon: Glad to see it's not huge, but I'm aiming to clear it. Thank you. Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 20:23, 6 November 2018 (UTC)
Good work. You must be exhausted. --Tagishsimon (talk) 21:32, 6 November 2018 (UTC)


I think that this discussion is resolved and can be archived. If you disagree, don't hesitate to replace this template with your comment. Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 20:23, 6 November 2018 (UTC)

Overview of places with names ending with same letters[edit]

Hi, I would like to see (on a map) all places in Germany with names ending with the same group of letters like "...büttel". The result would display places like Tremsbüttel, Hoisbüttel, Poppenbüttel etc. The challenge is, that the places are qualified very differently (and partly inconsistently) as "Gemeinde (Q15284)", "Gemeinde in Deutschland (Q262166)", "Ortsteil (Q253019)", Stadtteil (Q2983893), "Stadtteil von Hamburg (Q15830667)", "Stadt (Q515)" (and maybe more). Regards --Wikipeter-HH (talk) 10:40, 7 November 2018 (UTC)

@Wikipeter-HH: this sort of approach, Wikipeter; trying to union in the query below times-out, but you can run the P131* route or the P17 route on their own and get results (or, sometimes, a timeout). Or, I guess, look at a union of a bunch of P31=Q15284, Q262166, things, per the second example.
SELECT ?item ?itemLabel where 
{
#  {?item wdt:P131* wd:Q183.}
#  union
  {?item wdt:P17 wd:Q183.}
  ?item rdfs:label ?itemLabel. filter(lang(?itemLabel)="de")
  filter(strends(?itemLabel,"büttel"))
}
Try it!
SELECT ?item ?itemLabel where 
{
  values ?stuff {wd:Q15284 wd:Q262166 wd:Q253019 wd:Q2983893 wd:Q15830667 wd:Q515}
  ?item wdt:P31 ?stuff.
  ?item rdfs:label ?itemLabel. filter(lang(?itemLabel)="de")
  filter(strends(?itemLabel,"büttel"))
}
Try it! --Tagishsimon (talk) 13:40, 7 November 2018 (UTC)

Thanks for the quick reply Face-smile.svg --Wikipeter-HH (talk) 17:26, 7 November 2018 (UTC)

Challenge! An up to date map of Wikimedia movement affiliates[edit]

This map is out of date. Can we make a Wikidata-driven, up-to-date equivalent?

The static map of Wikimedia movement affiliate (Q5926733) on https://meta.wikimedia.org/wiki/Wikimedia_movement_affiliates is out of date. But we have data about all affiliates on Wikidata, don't we? Could anyone create a working query that produces a nice, up to date map? (And who knows, a display that can be shown on wiki with Kartographer?) Also, if anyone has any ideas to combine visualizations of geography-based and more 'thematic' user groups...? Spinster 💬 12:00, 7 November 2018 (UTC)

All items with an identifier assigned in a given administrative territorial entity including all the sub-territorial entities[edit]

In this case:

  • to get all items with an asigned identifier P3318 (an ID in a public monuments catalog)
  • inside a given P131 (in this case Q81802, Province of Almería), including all P131 members of Q81802.

Thanks in advance.

--Olea (talk) 12:38, 7 November 2018 (UTC)

@Olea: This
SELECT ?item ?itemLabel ?P3318 where 
{
  ?item wdt:P3318 ?P3318.
  ?item wdt:P131* wd:Q81802.
  SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
}
Try it! --Tagishsimon (talk) 13:20, 7 November 2018 (UTC)

♥♥♥

--Olea (talk) 12:01, 12 November 2018 (UTC)

EHRI authority control (Q51278630)[edit]

I'm trying to find all the data (which should be WWII camps and ghettos) in the EHRI authority files. Which query should I use for this?

Thanks in advance!

@Jjorna: This:
SELECT ?item ?itemLabel 
WHERE 
{
  ?item p:P528 ?statement.
  ?statement pq:P972 wd:Q51278630.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it! --Tagishsimon (talk) 15:01, 7 November 2018 (UTC)

Thanks for the quick reply!

List of subsidiary[edit]

i need a query which will list all the subsidiary of a given company.I just need the name of the subsidiary company. — Preceding unsigned comment added by 42.109.151.32 (talk) 8 november 2018 kl. 04.26 (UTC)‎

The following query lists also subsidiary (P355) in several steps to the company stated in the VALUES clause. Remove the '*' if you only want "direct" subsidiary (P355).
SELECT ?item ?itemLabel WHERE {
  VALUES ?parent_company { wd:Q95 }    #example, Q95=Google
  ?parent_company wdt:P355* ?item .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?itemLabel
Try it!
--Larske (talk) 06:57, 8 November 2018 (UTC)

Sparql query per estrazione dataset per lavorare sulla mia tesi - Extract dataset regarding an argument given by input[edit]

Hi everybody. I need a sparql query that extracts all wikidata items that are correlated to an specific argument given by input. In the end, I have to save the result in a local dump. For example, the argument could be "cardiology" or "computer security". Thank you all for the attention.


Salve. Avrei bisogno di una query che fosse in grado di estrarre tutti gli oggetti di wikidata di un determinato argomento dato come input e salvarli su un dump locale. Per esempio vorrei estrarre tutti gli oggetti che intercorrono nell'argomento "sicurezza informatica" o "cardiologia". Mi rendo conto che la computazione può essere onerosa ma verrà eseguita su macchine dedicate. Questo mi serve per poter applicare determinati algoritmi su tali dati e poterne analizzare manualmente il risultato: questo è un compito che si può pensare di eseguire solo su dataset ristretti rispetto che sull'intera wikidata. Se queste query sono già disponibili o non è la sezione adatta, per eventuali errori grammaticali, chiedo scusa. Buona giornata a tutti.

@Isabeauoliveri: Here is a starter query ... not sure how much it will help, but it probably covers the most obvious correlations of search term to wikidata item.
SELECT DISTINCT ?item ?itemLabel WHERE {
  values ?term {wd:Q10379}         #this is the input term
  {?item wdt:P31/wdt:P279* ?term .} #this gets instances of the term, or subclasses of the term
  UNION
  {?item wdt:P921 ?term .}           #this gets items which have the term as their main subject
  SERVICE wikibase:label { bd:serviceParam wikibase:language "it,en". }
}
Try it! --Tagishsimon (talk) 16:58, 8 November 2018 (UTC)

All female vs male writters born in a territorial entity including all the sub-territorial entities[edit]

I would like to compare by sex (P21) the number of female vs male writters born (P19) in a Spanish Autonomous communitie (Castilla y León). My main problem is P19 usually refers to a village, that belongs to a province, that belongs to an Autonomous communitie. And I would like to know the whole Castilla y León.

Thanks for considering my request

--Pablohn6 (talk) 13:51, 8 November 2018 (UTC)

@Pablohn6: Like this. wdt:P19/wdt:P131* wd:Q5739 says "born in, or born in a place that is in, Castilla y León".
SELECT DISTINCT ?genderLabel (count(?gender) as ?count) WHERE {

  ?item wdt:P106 wd:Q36180.
  ?item wdt:P19/wdt:P131* wd:Q5739.
  ?item wdt:P21 ?gender.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
} group by ?genderLabel
Try it! --Tagishsimon (talk) 14:46, 8 November 2018 (UTC)

Items starting or ending with a specific word[edit]

Greetings, I want a query for the items starting with a specfic words "James" which gives the result "James Bond, James Cameron" etc. --Titodutta (talk) 15:32, 8 November 2018 (UTC)

@Titodutta: You will not get that sort of a search across all items - far too many given that filtering for "James" is very inefficient. Best you can do is to cut down the search space by constraining the items you're going to test for Jamesness ... here, for instance, as a consolation, are ten spies called James.
SELECT ?item ?itemLabel 
WHERE 
{
  ?item wdt:P106 wd:Q9352089.
  ?item rdfs:label ?itemLabel. filter(lang(?itemLabel)="en")
  filter(strstarts(?itemLabel, "James"))
}
Try it! --Tagishsimon (talk) 16:25, 8 November 2018 (UTC)
A second approach is to look for items that have a given name of James, where the series ordinal property qualifier is 1, or where there is only one given name which is James. THat technique works, of course, only with values in wikidata that are codified ... does not work so well when looking for substrings of labels.
SELECT ?item ?itemLabel 
WHERE 
{
  {?item p:P735 ?statement.
  ?statement pq:P1545 "1" .
  ?statement ps:P735 wd:Q677191.}
  union
  {?item wdt:P735 wd:Q677191.
   minus {?item wdt:P735 ?thing. filter(?thing!=wd:Q677191)} 
  } 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }  
}
Try it! --Tagishsimon (talk) 16:36, 8 November 2018 (UTC)
  • Thank you for your kind support. --Titodutta (talk) 18:53, 9 November 2018 (UTC)

Wikipedia's by country[edit]

I'd like to know the "home" country of each Wikipedia. So, where would the different language Wikipedias (292) appear on a map as an indigenous or native language? I've tried to figure out the SPARQL query, but I'm very new to Wikidata.

It's an interesting question. You'd think a simple bit of SPARQL like the first query would answer it, but instead it times out.
SELECT ?item ?itemLabel ?lang ?langLabel ?country ?countryLabel
where 
{ ?item wdt:P31 wd:Q10876391. #find language wikipedias
  ?item wdt:P407 ?lang.       #get the wiki's 'language of work'
  ?country wdt:P463 wd:Q1065. #id countries by their membership of the UN
  ?country wdt:P37 ?lang.     #get the official languages of the country
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }  
}
Try it!
So instead we need to reach for a couple of named subqueries, one of which finds language wikipedias and their language, the other of which finds countries and their language ... these combine to give us a lookup from wikipedia to country via language.
SELECT ?item ?itemLabel ?lang ?langLabel ?country ?countryLabel
with 
{ select ?item ?lang where
{ ?item wdt:P31 wd:Q10876391. #find language wikipedias
  ?item wdt:P407 ?lang.       #get the wiki's 'language of work'
} } as %w
with
{ select ?country ?lang where
{ ?country wdt:P463 wd:Q1065. #id countries by their membership of the UN
  ?country wdt:P37 ?lang.     #get the official languages of the country
} } as %c
where
{ include %w
  include %c
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }  
}
Try it!
Note I have used the official language (P37) where you asked for "indigenous or native language" ... I'm not sure we have a better choice than P37, but if you find one, you can slot it in. I've also used membership of the United Nations as a proxy for defining an item as a country. The results suggest that not all language wikipedias have countries. As normal (for me) this is a rough & ready answer; doubtless you could spend some time refining and polishing it. --Tagishsimon (talk) 23:26, 8 November 2018 (UTC)
@Tagishsimon: Any insight on why the first query timeouts ? It seems not like it’ that a complex query … a join over a language, with both wikipedias having mostly one language and the same for languages … is it that the query engine does not really realize that and that you have to make him realize by precomputing the (almost) functional dependancies wp -> lang and coutry -> lang beforehand so that he can take advantage of this ? author  TomT0m / talk page 12:46, 9 November 2018 (UTC)
@TomT0m: No, I'm puzzled by it all. Fetching items on their own takes <3 seconds to return 314 rows; fetching countries on their own takes < 3 seconds to return 339 rows. Query 2 does the whole job in <3 seconds. Blazegraph documentation on Join Order Optimization suggests the use of hint:Query hint:optimizer "None" . or, later the use of a runtime query optimizer - hint:Query hint:optimizer "Runtime".. Adding either of these incantations makes query 1 work:
SELECT ?item ?itemLabel ?lang ?langLabel ?country ?countryLabel
where 
{ 
  ?item wdt:P31 wd:Q10876391. #find language wikipedias
  ?item wdt:P407 ?lang.       #get the wiki's 'language of work'
  ?country wdt:P463 wd:Q1065. #id countries by their membership of the UN
  ?country wdt:P37 ?lang.     #get the official languages of the country
 # hint:Query hint:optimizer "None" .
  hint:Group hint:optimizer "Runtime".
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }  
}
Try it!
but I don't understand how the query optimization could have gone so wrong in the first place. BG offers an explain service, but I've yet to get that to work through our interface. Right now, I'll take a wild guess that BG is trying to evaluate the ?item wdt:P407 ?lang. and ?country wdt:P37 ?lang. join before looking at ?item wdt:P31 wd:Q10876391. and ?country wdt:P463 wd:Q1065.. --Tagishsimon (talk) 14:00, 9 November 2018 (UTC)

Query showing the sum of statements per used property on selected items[edit]

Does anyone has an idea how to query the sum of the statements of each property of one item? The result should look something like this (for example for Q30):

property propertyLabel sum_statements
P31 instance of 5
P2131 nominal gdp 58
... ... ...

--Datawiki30 (talk) 21:45, 9 November 2018 (UTC)

@Datawiki30: Like this:
SELECT ?property ?propertyLabel (count(?property) as ?count)
where 
{ 
  values ?item {wd:Q12823}
  ?item ?property [].
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }  
} group by ?property ?propertyLabel
Try it! --Tagishsimon (talk) 21:50, 9 November 2018 (UTC)
If one only looks for Wikidata properties (no labels, sitelinks, meta stuff and so on), this one is showing real property labels:
SELECT ?property ?propertyLabel (COUNT(?property) AS ?count) WHERE { 
  wd:Q12823 ?p [] .
  ?property wikibase:claim ?p .
  SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }  
} GROUP BY ?property ?propertyLabel
Try it! MisterSynergy (talk) 22:15, 9 November 2018 (UTC)
Thank you both! Datawiki30 (talk) 13:27, 10 November 2018 (UTC)

List of (international) airports having only one runway[edit]

using the quantity (P1114) of runway (Q184590) for every international airport (Q644371) ? or via a count of runway (P529) ?Bouzinac (talk) 19:24, 11 November 2018 (UTC)

@Bouzinac: The second of those; I've provided P1114 values in the query below, but they're all null.
SELECT ?item  ?itemLabel (count(?runway) as ?runways) (sample(?quantity) as ?quantity) WHERE { 
  ?item wdt:P31 wd:Q644371.
  optional {?item wdt:P529 ?runway.}
  optional {?item wdt:P1114 ?quantity.}
  SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }  
} group by ?item ?itemLabel having (?runways=1) order by ?itemLabel
Try it! --Tagishsimon (talk) 20:05, 11 November 2018 (UTC)

Thanks!

Female librarians with no en.wp article[edit]

This is a simple enough query:

SELECT ?item WHERE { ?item wdt:P31 wd:Q5 . ?item wdt:P21 wd:Q6581072 . ?item wdt:P106 wd:Q182436 .

FILTER NOT EXISTS { ?wen schema:about ?item; schema:isPartOf <https://en.wikipedia.org/> . } }

However, when I add wdt:P279* for the subclasses of the occupation, the query crashes every time. Is there something that can be done to improve this query so it will not crash and include subclasses? Thank you. Gamaliel (talk) 17:50, 12 November 2018 (UTC)

@Gamaliel: It's always odd when WDQS fails on simple queries like this. I tried hint:Query hint:optimizer "None" . but that had no effect ... my supposition was that the query optimizer was erring. So that leaves the get-out-of-jail-free named subquery as the probable solution:
SELECT ?item with
{ select ?item where 
  {
  ?item wdt:P106/wdt:P279* wd:Q182436 .
  }
} as %i
where
{
  include %i
  ?item wdt:P31 wd:Q5 . 
  ?item wdt:P21 wd:Q6581072 . 
  FILTER NOT EXISTS { ?wen schema:about ?item; schema:isPartOf <https://en.wikipedia.org/> . } 
}
Try it! --Tagishsimon (talk) 17:57, 12 November 2018 (UTC)

Tagishsimon (talkcontribslogs) It worked! Thank you! Gamaliel (talk) 18:14, 12 November 2018 (UTC)

Merged people items with a Flanders Arts Institute identifier[edit]

27736 people on Wikidata have a Flanders Arts Institue person ID. Some of these items have since been merged with previously existing items on Wikidata. I am looking for a query that shows not only the current Q-number, but (if applicable) also the Q-number that has been merged with it. e.g.: Wim Vandekeybus no label (Q52189692) is merged with (and thus redirects to) (Wim Vandekeybus (Q3569237). Start of the query:

SELECT ?item ?itemLabel ?Flanders_Arts_Institute_person_ID 
WHERE { ?item wdt:P5068 ?Flanders_Arts_Institute_person_ID. 
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],nl". }
      }

Try it!

Beireke1 (talk) 09:30, 14 November 2018 (UTC)

@Beireke1: AFAIK, not happening. WDQS has no access to info on the fact that an item is a redirect. Quarry might be able to provide what you want (painfully, requiring crosstabulation between the WDQS result set of your query and the Quarry query) but that's still above my pay-grade. Any items returned by your query are substantive & not redirects, since by their nature a redirect has no statements & hence is not returned by the query. --Tagishsimon (talk) 09:43, 14 November 2018 (UTC)
Proof of that final assertion:
SELECT ?item ?itemLabel ?Flanders_Arts_Institute_person_ID WHERE 
{ 
  values ?item {wd:Q52189692}
  ?item wdt:P5068 ?Flanders_Arts_Institute_person_ID. 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],nl". }
}
Try it! --Tagishsimon (talk) 09:47, 14 November 2018 (UTC)

Merge multiple columns into one[edit]

Hello, what's wrong with this query ? I wished to concatenate ?FAA_USA ?Code_Transport_Canada ?DGAC ?russ ?FAArg into one column ?Local_Code.

SELECT DISTINCT ?airport ?airportLabel (SAMPLE(?coord) AS ?coord) ?ICAO ?IATA 
(sample(?FAA_USA ?Code_Transport_Canada ?DGAC ?russ ?FAArg) AS ?Local_Code) WHERE {
?airport (wdt:P31/wdt:P279*) wd:Q62447.
?airport wdt:P17 wd:Q236.
MINUS { ?airport wdt:P576 _:b2. }                                # remove items with P576 (dissolved, abolished or demolished) as a main property
MINUS { ?airport (wdt:P31/wdt:P279*) wd:Q695850. }               # exclude military airports
MINUS { ?airport (wdt:P31/wdt:P279*) wd:Q1311670. }              # exclude railways stations
MINUS { ?airport (wdt:P31/wdt:P279*) wd:Q7373622. }              # exclude Royal Air Force
MINUS { ?airport (wdt:P31/wdt:P279*) wd:Q502074. }               # exclude héliports
MINUS { ?airport wdt:P31/wdt:P279* wd:Q2265915.}                 # exclude vol à voile/gliders
MINUS { ?airport (wdt:P31/wdt:P279*) wd:Q44665966. }             # exclude  airports being build
MINUS { ?airport (wdt:P31/wdt:P279*) wd:Q782667. }               # exclude motorways where plane can land
MINUS { ?airport wdt:P582 _:b3. }                                # remove items with P582 (end date) as a main property
MINUS { ?airport a wdno:P17.}                                    # exclude airports that aren't physically based in a country
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
OPTIONAL { ?airport wdt:P625 ?coord. }
OPTIONAL { ?airport wdt:P239 ?ICAO. }
OPTIONAL { ?airport wdt:P238 ?IATA. }
OPTIONAL { ?airport wdt:P240 ?FAA_USA. }
OPTIONAL { ?airport wdt:P5699 ?Code_Transport_Canada. }
OPTIONAL { ?airport wdt:P5746 ?DGAC. }
OPTIONAL { ?airport wdt:P5851 ?russ. }
OPTIONAL { ?airport wdt:P6120 ?FAArg. }
}
GROUP BY ?airport ?airportLabel ?ICAO ?IATA ?Local_Code
ORDER BY ?coord

Try it! Bouzinac (talk) 10:25, 14 November 2018 (UTC)

Several things. You'd need to use GROUP_CONCAT as an aggregate function if you wanted to aggregate the values ... but you have ?Local_Code as a GROUP, so maybe you;d be better using BIND(concat(?FAA_USA, ?Code_Transport_Canada, ?DGAC, ?russ, ?FAArg) AS ?Local_Code) in the body of the query, and a simple Local_code with no aggregation (i.e. no SAMPLE) in the select. That aside, there is no data in any of ?FAA_USA, ?Code_Transport_Canada, ?DGAC, ?russ, ?FAArg for the data returned by your query, so far as my experiments have shown. --Tagishsimon (talk) 10:51, 14 November 2018 (UTC)
Does this looks like what you are looking for ?
SELECT DISTINCT ?airport ?airportLabel (SAMPLE(?coord) AS ?coord) ?ICAO ?IATA (sample(?Local_Code) as ?lcode) {
  ?airport (wdt:P31/wdt:P279*) wd:Q62447;
           wdt:P17 wd:Q236.
  MINUS { ?airport wdt:P576 _:b2. }                                # remove items with P576 (dissolved, abolished or demolished) as a main property
  MINUS { ?airport (wdt:P31/wdt:P279*) wd:Q695850. }               # exclude military airports
  MINUS { ?airport (wdt:P31/wdt:P279*) wd:Q1311670. }              # exclude railways stations
  MINUS { ?airport (wdt:P31/wdt:P279*) wd:Q7373622. }              # exclude Royal Air Force
  MINUS { ?airport (wdt:P31/wdt:P279*) wd:Q502074. }               # exclude héliports
  MINUS { ?airport wdt:P31/wdt:P279* wd:Q2265915.}                 # exclude vol à voile/gliders
  MINUS { ?airport (wdt:P31/wdt:P279*) wd:Q44665966. }             # exclude  airports being build
  MINUS { ?airport (wdt:P31/wdt:P279*) wd:Q782667. }               # exclude motorways where plane can land
  MINUS { ?airport wdt:P582 _:b3. }                                # remove items with P582 (end date) as a main property
  MINUS { ?airport a wdno:P17.}                                    # exclude airports that aren't physically based in a country
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
   
  OPTIONAL { ?airport wdt:P625 ?coord. }
  OPTIONAL { ?airport wdt:P239 ?ICAO. }
  OPTIONAL { ?airport wdt:P238 ?IATA. }
   
  OPTIONAL { ?airport wdt:P240 ?Local_Code. }
  OPTIONAL { ?airport wdt:P5699 ?Local_Code. }
  OPTIONAL { ?airport wdt:P5746 ?Local_Code. }
  OPTIONAL { ?airport wdt:P5851 ?Local_Code. }
  OPTIONAL { ?airport wdt:P6120 ?Local_Code. }
}
GROUP BY ?airport ?airportLabel ?ICAO ?IATA
ORDER BY ?coord
Try it!
Colour me unconvinced, T0mt0m. Surely that just overwrites values into ?Local_Code meaning you get whatever the last value is. Equally, what do I know about SPARQL - my concat suggestion seems on testing to be too simple ... I find if there's no value for one of the variables, the concat fails. So right now I'm advocating the following rather ponderous route, where you test each variable before finally concatenating them all. By now, I've somewhat bowdelerised the query, since as I said, there's no data to be concatenated for the original query:
SELECT DISTINCT ?airport ?airportLabel ?ICAO ?IATA ?FAA_USA ?6 {
  ?airport (wdt:P31/wdt:P279*) wd:Q62447.
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }   
  OPTIONAL { ?airport wdt:P239 ?ICAO. }
  OPTIONAL { ?airport wdt:P238 ?IATA. }
  ?airport wdt:P240 ?FAA_USA. 
  OPTIONAL { ?airport wdt:P5699 ?Code_Transport_Canada. }
  ?airport wdt:P5746 ?DGAC. 
  OPTIONAL { ?airport wdt:P5851 ?russ. }

  bind(if(bound(?FAA_USA),?FAA_USA,"") as ?1)
  bind(if(bound(?Code_Transport_Canada),?Code_Transport_Canada,"") as ?2) 
  bind(if(bound(?DGAC),?DGAC,"") as ?3) 
  bind(if(bound(?russ),?russ,"") as ?4)
  bind(if(bound(?FAArg),?FAArg,"") as ?5)
  bind(concat(?1,"; ",?2,"; ",?3,"; ",?4,"; ",?5) as ?6)
}
limit 10
Try it!
and here it is for the original query...
SELECT DISTINCT ?airport ?airportLabel (SAMPLE(?coord) AS ?coord) ?ICAO ?IATA ?Local_Code WHERE {
?airport (wdt:P31/wdt:P279*) wd:Q62447.
?airport wdt:P17 wd:Q236.
MINUS { ?airport wdt:P576 _:b2. }                                # remove items with P576 (dissolved, abolished or demolished) as a main property
MINUS { ?airport (wdt:P31/wdt:P279*) wd:Q695850. }               # exclude military airports
MINUS { ?airport (wdt:P31/wdt:P279*) wd:Q1311670. }              # exclude railways stations
MINUS { ?airport (wdt:P31/wdt:P279*) wd:Q7373622. }              # exclude Royal Air Force
MINUS { ?airport (wdt:P31/wdt:P279*) wd:Q502074. }               # exclude héliports
MINUS { ?airport wdt:P31/wdt:P279* wd:Q2265915.}                 # exclude vol à voile/gliders
MINUS { ?airport (wdt:P31/wdt:P279*) wd:Q44665966. }             # exclude  airports being build
MINUS { ?airport (wdt:P31/wdt:P279*) wd:Q782667. }               # exclude motorways where plane can land
MINUS { ?airport wdt:P582 _:b3. }                                # remove items with P582 (end date) as a main property
MINUS { ?airport a wdno:P17.}                                    # exclude airports that aren't physically based in a country
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
OPTIONAL { ?airport wdt:P625 ?coord. }
OPTIONAL { ?airport wdt:P239 ?ICAO. }
OPTIONAL { ?airport wdt:P238 ?IATA. }
OPTIONAL { ?airport wdt:P240 ?FAA_USA. }
OPTIONAL { ?airport wdt:P5699 ?Code_Transport_Canada. }
OPTIONAL { ?airport wdt:P5746 ?DGAC. }
OPTIONAL { ?airport wdt:P5851 ?russ. }
OPTIONAL { ?airport wdt:P6120 ?FAArg. }
  bind(if(bound(?FAA_USA),?FAA_USA,"") as ?1)
  bind(if(bound(?Code_Transport_Canada),?Code_Transport_Canada,"") as ?2) 
  bind(if(bound(?DGAC),?DGAC,"") as ?3) 
  bind(if(bound(?russ),?russ,"") as ?4)
  bind(if(bound(?FAArg),?FAArg,"") as ?5)
  bind(concat(?1,"; ",?2,"; ",?3,"; ",?4,"; ",?5) as ?Local_Code)  
}
GROUP BY ?airport ?airportLabel ?ICAO ?IATA ?Local_Code
ORDER BY ?coord
Try it! --Tagishsimon (talk) 11:25, 14 November 2018 (UTC)
@Tagishsimon: The original author used « sample » which in my opinion implies that he wants any of the value. It’s perfectly possible considering the usecase that there is only one of the code possible local code for any of the airport which would mean that sample will always choose the one possible value. But there is probably a way to write the query in a totally different spirit to avoid this, for example « optional {?airport ?code_prop ?code_val values ?code_prop { wdt:P240 wdt:P5699 wdt:P5746 wdt:P5851 dt:P6120 } would probably work, and by not selecting all the airports and excluding some subkinds but selecting the right kinds in the first place. This would mean a « explain to me what you want, I’ll tell you how to avoid this » that is unfortunately usually not always welcome by the teller :) author  TomT0m / talk page 11:34, 14 November 2018 (UTC)
I see where you're coming from :). --Tagishsimon (talk) 11:43, 14 November 2018 (UTC)
Hello, well, you pointed out the fact an airport can happen to have only one local code. (albeit the fact there two or three canadiano-USA airports that have both Canada and USA code). So I thought the sample function would pick the first non-NULL code. I'll test out your results by filtering some countries. And return to you :) Bouzinac (talk) 15:24, 14 November 2018 (UTC)
Taking the "  OPTIONAL { ?airport wdt:P240 ?Local_Code. }

  OPTIONAL { ?airport wdt:P5699 ?Local_Code. }

  OPTIONAL { ?airport wdt:P5746 ?Local_Code. }

  OPTIONAL { ?airport wdt:P5851 ?Local_Code. }

  OPTIONAL { ?airport wdt:P6120 ?Local_Code. }" solution, works really well and looks to be slightly quicker. Thanks all! Bouzinac (talk) 20:54, 14 November 2018 (UTC)

WDQS servers not all up to date?[edit]

Hi all, this query does not seem to return all items:

SELECT ?item ?catcode WHERE { 
  ?item p:P528 [ pq:P972 wd:Q53207781 ; ps:P528 ?catcode]. 
}

Try it!

You can see what items should be in there by clicking "what links here" on Adam Pynacker catalog raisonné, 1926 (Q53207781). So e.g. this item is missing: Landscape with Hunters (Q31158443) is missing. Any idea why? Magnus suggested opening a phab task but I wanted to check in here first. This affects a lot of listeria lists that I manage. Thx in advance, Jane023 (talk) 12:07, 14 November 2018 (UTC)

@Jane023: Maybe check out https://phabricator.wikimedia.org/T208928 on your route to https://phabricator.wikimedia.org/T203646 ... this seems to be where the action on this point probably is - the various WDQS replicas are out of synch, to the tune of 40 million triples - see triples graph on https://grafana.wikimedia.org/dashboard/db/wikidata-query-service?orgId=1
Your issue may be different, of course ... so like this - https://phabricator.wikimedia.org/T208925 - where WDQS seemed oblivious of an update done in July 2018.
I guess another data point will not hurt; so don't hesitate to phab the problem. Your ticket can always be closed, as T208925 has been. --Tagishsimon (talk) 13:17, 14 November 2018 (UTC)
Thanks! This looks to be T207675 (I only read about 4 or 5 of that thread and this one explicitly mentions the same problem with a qualifier. I will follow that one and add a link back here. Jane023 (talk) 14:09, 14 November 2018 (UTC)

Uploads with timestamps[edit]

With this API call I get the recent uploads of my bot. So I would like this in SPARQL to make an overview of the number of uploads per day for the last couple of days.

SELECT * {
  SERVICE wikibase:mwapi {
    bd:serviceParam wikibase:endpoint "commons.wikimedia.org" .
    bd:serviceParam wikibase:api "Generator" .
    bd:serviceParam mwapi:generator "allimages" .
    bd:serviceParam mwapi:gaiuser "BotMultichillT" .
    bd:serviceParam mwapi:gaisort "timestamp" .
    bd:serviceParam mwapi:gaidir "older" .
    ?title wikibase:apiOutput mwapi:title .
    ?timestamp wikibase:apiOutput mwapi:timestamp .
  }

} LIMIT 100

Try it!

But this query just gives the same timestamp (now) for all files. Any idea how to get the actual upload time? Than I can extract the year/month/day, group by it to get a count and maybe even generate a nice graph. Multichill (talk) 11:10, 15 November 2018 (UTC)

All newspapers and magazines in Basque language[edit]

Hello! I'm trying to make something rather simple, but I get a timeout message every time I try. There must be an error somehwere...

SELECT ?aldizkako_argitalpen ?aldizkako_argitalpenLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?aldizkako_argitalpen wdt:P31* wd:Q1002697.
  ?aldizkako_argitalpen wdt:P407 wd:Q143.
}

Try it!

Thanks! -Theklan (talk) 15:33, 15 November 2018 (UTC)

here ya go! CalvinBall (talk) 15:49, 15 November 2018 (UTC)
SELECT ?a ?aLabel WHERE {
  ?a wdt:P31/wdt:P279* wd:Q1002697.
  ?a wdt:P407 wd:Q143.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

@CalvinBall: Thanks, but this query doesn't cover newspapers, that also a kind of periodic publication. -Theklan (talk) 20:44, 15 November 2018 (UTC)
@Theklan: There was a typo in Calvin's query, now corrected. Here, FYI, is a count of the P31 types of items that have a language of work or name (P407) of Esperanto (Q143), in case there are other things that might be of interest to you.
SELECT ?P31 ?P31Label (count(?P31) as ?count)  WHERE {
  ?a wdt:P407 wd:Q143 .
  ?a wdt:P31 ?P31.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} group by ?P31 ?P31Label order by desc(?count)
Try it! --Tagishsimon (talk) 21:02, 15 November 2018 (UTC)
@Tagishsimon: eeerrr... no... this counts all the kind of things in a given language, but doesn't show which are the publications in a given language, that was the query giving timeout. -Theklan (talk) 21:11, 15 November 2018 (UTC)
@Theklan: Indeed. I have corrected Calvin's query (i.e. edited the query that he wrote), and provided a different query which counts things. Run Calvin's query again. All will be good. If in doubt, look at the diff for my first edit and you'll see I changed a wd: to a wdt: - --Tagishsimon (talk) 21:19, 15 November 2018 (UTC)
@Tagishsimon: Right! Thanks, just misunderstood your message. This works! -Theklan (talk) 21:48, 15 November 2018 (UTC)

Fuse[edit]

Cañón El Dorado (Q5351174) y Cañón El Dorado (Q49800146). Gracias --Ortisa (talk) 17:53, 15 November 2018 (UTC)

done --Tagishsimon (talk) 18:02, 15 November 2018 (UTC)

norwegian citizens[edit]

Is it possibele to have a list of Norwegian Peoples born between 1840 to 1945. But not listening person who died before 1939. Breg Pmt (talk) 02:41, 16 November 2018 (UTC)

@Pmt: Here's a quick & dirty version ... you have some very old people in Norway. Main points:
  • It ignores date precision - watch out for people born on the turn of the century
  • It is based on country of citizenship, not, for instance place of birth
  • Adjust the dates if you do not want 1840-1945 inclusive, etc
  • date of death is optional - if null, and the dob condition is met, then the item is selected.
  • you'll get multiple rows for people with multiple dobs or dods
  • Let us know if you want any of the above addressing, or any other tweaks
  • Oh - I've given you a calculated age, which might come in handy. Obviously your 174-year olds are problematic :)
SELECT ?item ?itemLabel ?dob ?dod ?age WHERE 
{ 
  ?item wdt:P27 wd:Q20 .
  ?item wdt:P569 ?dob .
  optional {?item wdt:P570 ?dod .}
  filter(year(?dod) > 1938|| !bound(?dod))
  filter(year(?dob) > 1839 )
  filter(year(?dob) < 1946 )
  bind(coalesce(year(?dod),2018) as ?dod2)      
  bind(?dod2-year(?dob) as ?age)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],no". }
}
Try it! --Tagishsimon (talk) 02:56, 16 November 2018 (UTC)
@Tagishsimon: Exactly what I needed. All this people lived during WW2 in Norway, and should be included among the 50000 who fled to Sweden or among 15000 people served in the Norwegian mercant fleet or navy or the 10000 ki lled in Norway? The identificators and sources are available on paper.
Old Norwegians? they are dipped in Norwegian North sea oil, and then just slip away. Breg Pmt (talk) 03:55, 16 November 2018 (UTC)
I suspect the Rakfisk --Tagishsimon (talk) 10:53, 16 November 2018 (UTC)
@Pmt: More seriously, I've amended the query - it was finding people with dods outside the range you were interested in. Now fixed. --Tagishsimon (talk) 11:17, 16 November 2018 (UTC)


@Tagishsimon: Nice, I now have 15600 instead of 18500. Breg Pmt (talk) 11:27, 16 November 2018 (UTC)
There's no rush, Pmt. Based on your countrymen & women, you'll be living to about age 150. Plenty of time. --Tagishsimon (talk) 11:28, 16 November 2018 (UTC)
Leaning on this The Government Pension Fund of Norway (Q1196231) it should not be a problem Pmt (talk) 11:59, 16 November 2018 (UTC)

Show media possible reach[edit]

Hello! I have built a query with items operating area, and want to show it in a bubble chart... but I want to add the results of different operating areas in the same item. For example, if somethingis operationg in Germany and Sweden, I don't want to show it twice, but with both populations aggregated. I'm doing something wrong:

SELECT ?KomLabel ?q WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?Kom wdt:P31 wd:Q340169.
  ?Kom wdt:P407 wd:Q8752.
  ?Kom wdt:P2541 ?op.
  ?op wdt:P1082 ?q.
}
GROUP by ?KomLabel

Try it!

-Theklan (talk) 12:16, 16 November 2018 (UTC)

@Theklan: Probably just:
SELECT ?KomLabel (sum(?q) as ?q) WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?Kom wdt:P31 wd:Q340169.
  ?Kom wdt:P407 wd:Q8752.
  ?Kom wdt:P2541 ?op.
  ?op wdt:P1082 ?q.
}
GROUP by ?KomLabel
Try it! --Tagishsimon (talk) 12:21, 16 November 2018 (UTC)

UK MPs[edit]

Two separate, but related, queries, please:

  • Members of the United Kingdom parliament with no English Wikipedia article
  • Members of the United Kingdom parliament with no image.

Cheers. Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 12:37, 16 November 2018 (UTC)

@Pigsonthewing: Presuming for all parliaments? Change Q16707842 to Q30524710 if you just want the current parliament (spoiler - all have articles, 24 are missing images).
# No en.wiki article
SELECT distinct ?item ?itemLabel with 
{
  select distinct ?item where
  {  ?item wdt:P39/wdt:P279* wd:Q16707842 . }
} as %i
where
{include %i
  filter not exists {?article schema:about ?item ;
          schema:isPartOf <https://en.wikipedia.org/> .}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!
# No image
SELECT distinct ?item ?itemLabel with 
{
  select distinct ?item where
  {  ?item wdt:P39/wdt:P279* wd:Q16707842 . }
} as %i
where
{include %i
  filter not exists {?item wdt:P18 [] .}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it! --Tagishsimon (talk) 12:52, 16 November 2018 (UTC)