Wikidata:Request a query

Latest comment: 1 day ago by Kippelboy in topic Filtering by enddate in a property

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 queries [Q114898838] can be requested. Please provide feedback if a query is written for you.

You can also request help to rewrite queries that don't work anymore, due to the WDQS graph split.

For sample queries, see Examples and Help:Dataset sizing. 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 and Wikidata:SPARQL query service/query optimization.

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

To report an issue about the Query Service (interface, results views, export...) please see Wikidata:Contact the development team/Query Service and search.
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 2024/08.

How to get this query to not time out?

edit

I am trying to see a list of all the "Good Articles" of Wikipedia that don't have parallel articles on the Hebrew Wikipedia, but unfortunately whenever I run it, it times out. This is the current query:

SELECT DISTINCT ?article ?articleLabel (COUNT(DISTINCT ?sitelink_other) AS ?cnt) 
WHERE {
  # Identify articles that are "Good Articles" on English Wikipedia
  ?sitelink wikibase:badge wd:Q17437798;  # item is a "Good Article"
            schema:about ?article;
            schema:isPartOf <https://en.wikipedia.org/>.

  # Exclude items that have a sitelink to the Hebrew Wikipedia
  MINUS {
    ?sitelink_he schema:about ?article; schema:isPartOf <https://he.wikipedia.org/>.
  }
  
  # Count the number of interwiki sitelinks
  ?sitelink_other schema:about ?article.
  
  # Include labels
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?article ?articleLabel 
ORDER BY DESC(?cnt) # order by the count of interwiki sitelinks in descending order
Try it!

Does any one know how I can fix the query for it to work? WikiJunkie (talk) 18:36, 25 August 2024 (UTC)Reply

Apparently now it worked! and it produced 32,206 items! Do some queries not work consistently for some reason? WikiJunkie (talk) 18:38, 25 August 2024 (UTC)Reply
edit

Does anyone know why this query does not sort the results by the amount of interwiki links each article has? (the top item on this list says that the CNT=585 while in reality it is 38)

SELECT DISTINCT ?movie ?movieLabel (COUNT(?sitelink) AS ?cnt) 
WHERE {
  ?movie wdt:P31 wd:Q11424. # item is a film
  ?movie wdt:P577 ?release_date. # item has a publication date (release date)
  FILTER (?release_date >= "1980-01-01T00:00:00Z"^^xsd:dateTime && ?release_date < "1990-01-01T00:00:00Z"^^xsd:dateTime) # filter by date range
  ?sitelink schema:about ?movie.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  MINUS {
    _:article schema:about ?movie; schema:isPartOf <https://he.wikipedia.org/>. # exclude items with an article on hewiki
  }
}
GROUP BY ?movie ?movieLabel 
ORDER BY DESC(?cnt) # order by the count of sitelinks in descending order
Try it!

WikiJunkie (talk) 13:49, 20 August 2024 (UTC)Reply

You can COUNT(DISTINCT ?sitelink) or instead have ?movie wikibase:sitelinks ?cnt. Flipping Switches (talk) 23:12, 20 August 2024 (UTC)Reply
Thanks! WikiJunkie (talk) 18:32, 25 August 2024 (UTC)Reply

Searching for items that exist on multiple editions of Wikipedia

edit

I am searching for instance/sub-classes of LGBT+ identity (Q115870510) that have 3 or more non-English Wikipedia site-links. I attempted a query here, however it times-out. I will commit to improving documentation so that it is easier for others trying similar queries https://w.wiki/AszG

SELECT ?item ?itemLabel ?linkcount WHERE {  
?item wdt:P31/wdt:P279* wd:Q115870510 .
?item wikibase:sitelinks ?linkcount .

  FILTER (?linkcount >= 10) . 
  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 " 
 [AUTO_LANGUAGE],en". }
}

ORDER BY DESC(?linkcount)
Try it!

Shushugah (talk) 11:19, 10 August 2024 (UTC)Reply

SELECT ?item ?itemLabel ?linkcount WHERE {
  # instance of LGBT  
  ?item wdt:P31/wdt:P279* wd:Q115870510 ;
        wikibase:sitelinks ?linkcount .
  FILTER(?linkcount > 2)
  MINUS {
    ?article schema:about ?item ;
             schema:isPartOf <https://en.wikipedia.org/>
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
ORDER BY DESC(?linkcount)
Try it!
Flipping Switches (talk) 13:34, 10 August 2024 (UTC)Reply
Each FILTER and MINUS alone gives results, but they don't intersect. Flipping Switches (talk) 09:00, 17 August 2024 (UTC)Reply

Lexemes with mismatching reading patterns

edit

I need a list of lexemes that have forms with diverging values for sinogram reading pattern (P5244) in order to find lexemes that should be split. Thank you 🙏 – Shisma (talk) 07:48, 14 August 2024 (UTC)Reply

@Shisma: could you give a bit more context? I had a quick look at lexeme's forms using sinogram reading pattern (P5244), like Lexeme:L8441#F1 but I'm not sure where I should look for a divergence? Do you mean when there is two values like on Lexeme:L640276#F1 and Lexeme:L640276#F1? (which are currently the only two forms in that case see https://w.wiki/Ayxi). Cheers, VIGNERON (talk) 16:30, 22 August 2024 (UTC)Reply
@VIGNERON:. Sorry. I should have provided an example. I meant a situation like this. One Lexeme, multiple forms with different reading patterns. – Shisma (talk) 17:32, 22 August 2024 (UTC)Reply
@Shisma: no problem, so you mean like this:
SELECT * WHERE {
  ?l ontolex:lexicalForm ?f1 ;
     ontolex:lexicalForm ?f2 .
  ?f1 wdt:P5244 ?value1 .
  ?f2 wdt:P5244 ?value2 .
  FILTER ( ?value1 != ?value2 )
}
Try it!
1234 results right now (I didn't de-duplicate lexemes as you may want to know that information, here is the same query with unique lexemes : https://w.wiki/AzBv and 322 results). Cheers, VIGNERON (talk) 06:34, 23 August 2024 (UTC)Reply

List of countries and regions which were at the 2024 Olympics, by population

edit

Hi all. Is there any way we can generate a list of those regions and nations which took part in this year's Olympic games, or a list of those which have a National Olympic Committee (Q183288)? Listed by population, please. Cheers! Llywelyn2000 (talk) 09:49, 15 August 2024 (UTC)Reply

German Bundesländer (Q1221156) and their Cities (Q515)

edit

I need a list of german cities sorted by Bundesland (state, Q1221156). The result of my query is only 20 items. Is there a better way to query cities by bundesland?

SELECT ?state ?stateLabel ?city ?cityLabel WHERE {
  ?state wdt:P31 wd:Q1221156;
    wdt:P150 ?city.
  ?city (wdt:P31/(wdt:P279*)) wd:Q515.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY (?stateLabel) (?cityLabel)
Try it!

Marlons Friends (talk) 10:51, 20 August 2024 (UTC)Reply

I see 151 result. --Infovarius (talk) 19:43, 20 August 2024 (UTC)Reply
@Marlons Friends, Infovarius: I also see 151 results with a lot of duplication, and 44 results with DISTINCT. Both seems low.
Instead of taking the states and then looking for city in it, I tried the symmetric approach: taking the cities and looking for the states, it gives a bit more results (81 right now) :
SELECT DISTINCT ?city ?cityLabel ?land ?landLabel WHERE {
  ?city wdt:P31/wdt:P279* wd:Q515 ;
        wdt:P17 wd:Q183 ;
        wdt:P131 ?land .
  ?land wdt:P31 wd:Q1221156 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en". }
}
Try it!
I found that some cities are not directly indicated as in the Land but in something itself in the Land. The query is then bigger, but doable on the QLever endpoint like this : https://qlever.cs.uni-freiburg.de/wikidata/a2MhLM and it gives a lot more results (you need to download them to see them all unlike on the Wikidata Query Service).
PS: also, do you want only the cities and all communes (Gemeinde). Cheers, VIGNERON (talk) 07:03, 23 August 2024 (UTC)Reply
@ Infovarius: Thank you. it seems that most cities in wikidata simply are not connected to "Bundesländer"?
@ VIGERON: Thank you, that is an incredible insight. I did not know qlever. I have been testing this https://qlever.cs.uni-freiburg.de/wikidata/6QLofu#csv and got more than 100k results. It seems I got more or less all populated places in Germany with their Bundesland and coordinates. That was what I needed. Are there more places or would it even be smarter to query OSM? Marlons Friends (talk) 13:51, 23 August 2024 (UTC)Reply

List of items "described by source" starting with a specific letter in the qualifier "section, verse, paragraph, or clause"

edit

Hi! How can I create a list of items that are described by a source (P1343), for example Q867541, that statement has the qualifier section, verse, paragraph, or clause (P958), that qualifier starts with, let's say, letter "M", and get those items sorted in alphabetical order (sorted by P958 value), getting the qualifiers volume (P478) and page (P304) too? Thanks in advance. strakhov (talk) 17:57, 21 August 2024 (UTC)Reply

@Strakhov: hmm, are you sure of what you asked? Apparently, section, verse, paragraph, or clause (P958) is almost never used for Encyclopædia Britannica 11th edition (Q867541). This query only give one result:
SELECT ?q ?section WHERE {
  ?q p:P1343 ?node .
  ?node ps:P1343 wd:Q867541 ;
        pq:P958 ?section .
  FILTER ( STRSTARTS(?section, "M" ) )
}
Try it!
Cheers, VIGNERON (talk) 16:25, 22 August 2024 (UTC)Reply
Thanks a lot, VIGNERON. It was a random encyclopedia item. Actually I had in mind a few other reference works. strakhov (talk) 16:30, 22 August 2024 (UTC)Reply
@Strakhov: ah ok, here is the same query but for Brockhaus Enzyklopädie (19 ed.) (Q17377889) and with the optional qualifier.
SELECT ?q ?section ?volume ?page WHERE {
  ?q p:P1343 ?node .
  ?node ps:P1343 wd:Q17377889 ;
        pq:P958 ?section .
  FILTER ( STRSTARTS(?section, "M" ) )
  OPTIONAL { ?node pq:P304 ?page }
  OPTIONAL { ?node pq:P478 ?volume }
}
Try it!
Cheers, VIGNERON (talk) 06:41, 23 August 2024 (UTC)Reply

Trying to finding a 1 line mul solution reveals a bug

edit

The upcoming mul change needs single line label/FILTER statements replaced with 3 line ones. In an attempt to circumvent this I coded

SELECT DISTINCT ?item ?qcount ?qlabel ?quantity WHERE{
  VALUES ?item {wd:Q17122887}
   { ?item p:P516 [ps:P516 ?qname; pq:P1114 ?qcount].
   SERVICE wikibase:label {bd:serviceParam wikibase:language "en,mul".
     ?qname rdfs:label ?qlabel.
   }
    #works
    #BIND(CONCAT(" ",?qlabel) AS ?quantity)
    # does not work
    BIND(CONCAT(STR(?qcount)," ",?qlabel) AS ?quantity)
  }
}
Try it!

But the concatenation of 2 variables does not work. This smells like a bug to me. Vicarage (talk) 06:46, 23 August 2024 (UTC)Reply

@Vicarage: what doesn't work exactly? or what did you expect? I do see the query doing what is asked and "16 Draco" correctly concatenated in the last column. Also, these items have a "en" label but no "mul" labels ; for checking, I tried with different items with "mul" labels and it also worked. Cheers, VIGNERON (talk) 09:24, 23 August 2024 (UTC)Reply

Oops, its using qname that fails, not qcount. The mul bit works fine, I tested it on en,de for other stuff

SELECT DISTINCT ?item ?qcount ?qlabel ?quantity WHERE{
  VALUES ?item {wd:Q17122887}
   { ?item p:P516 [ps:P516 ?qname; pq:P1114 ?qcount].
   SERVICE wikibase:label {bd:serviceParam wikibase:language "en,mul".
     ?qname rdfs:label ?qlabel.
   }
    # works
    #BIND(CONCAT(" ",?qlabel) AS ?quantity)
    # works 
    # BIND(CONCAT(STR(?qcount)," ",?qlabel) AS ?quantity)
    # does not work
    BIND(CONCAT(STR(?qname)," ",?qlabel) AS ?quantity)
  }
}
Try it!
@Vicarage: indeed, this is a strange bug. Especially as it works if you do it in 2 lines :
SELECT DISTINCT ?item ?qcount ?qlabel ?quantity WHERE{
  VALUES ?item {wd:Q17122887}
   { ?item p:P516 [ps:P516 ?qname; pq:P1114 ?qcount].
   SERVICE wikibase:label {bd:serviceParam wikibase:language "en,mul".
     ?qname rdfs:label ?qlabel.
   }

    BIND(STR(?qname) AS ?qnameSTR)
    BIND(CONCAT(?qnameSTR," ",?qlabel) AS ?quantity)
  }
}
Try it!
I'm guessing the problem is caused by ?qname being an URI but it still odd... @Lucas Werkmeister: any idea what is happening?
Cdlt, VIGNERON (talk) 10:48, 23 August 2024 (UTC)Reply
In my experience using the label service’s output anywhere other than the SELECT only works reliably with a named subquery:
SELECT DISTINCT ?item ?qcount ?qlabel ?quantity1 ?quantity2 ?quantity3 WITH {
  SELECT ?item ?qname ?qcount ?qlabel WHERE {
    VALUES ?item {wd:Q17122887}
    ?item p:P516 [ps:P516 ?qname; pq:P1114 ?qcount].
    SERVICE wikibase:label {
      bd:serviceParam wikibase:language "en,mul".
      ?qname rdfs:label ?qlabel.
    }
  }
} AS %results WHERE {
  INCLUDE %results.
  # works
  BIND(CONCAT(" ",?qlabel) AS ?quantity1)
  # works 
  BIND(CONCAT(STR(?qcount)," ",?qlabel) AS ?quantity2)
  # does not work
  BIND(CONCAT(STR(?qname)," ",?qlabel) AS ?quantity3)
}
Try it!
Lucas Werkmeister (talk) 14:17, 24 August 2024 (UTC)Reply
disappointing news for anyone hoping that mul could be introduced with minimum disruption. The FILTER approach does seem reliable, so I guess I will stick to that. Vicarage (talk) 15:19, 24 August 2024 (UTC)Reply

Query Commons files and structured data

edit

I'm able to return the files within a category, but I would like to return some structured data as well. I got this far but i'm unsuccessful with the later part.

SELECT ?file ?url ?title
WHERE {
  VALUES ?categories { 
   "Category:Vidéos LSF par Laura Jauvert"
  }
  SERVICE wikibase:mwapi {
    bd:serviceParam wikibase:api "Generator" ;
                    wikibase:endpoint "commons.wikimedia.org" ;
                    mwapi:gcmtitle ?categories ;
                    mwapi:generator "categorymembers" ;
                    mwapi:gcmtype "file" ;
                    # mwapi:prop "P407" ; # I have no clue how to query strucured data P407
                    mwapi:gcmlimit "max" .
    ?title wikibase:apiOutput mwapi:title .
    ?pageid wikibase:apiOutput "@pageid" .
    #?lang wikibase:apiOutput mwapi:prop.
  }
  BIND (URI(CONCAT('https://commons.wikimedia.org/entity/M', ?pageid)) AS ?file)
  BIND (URI(CONCAT('https://commons.wikimedia.org/wiki/', ?title)) AS ?url)  
}
Try it!

All the files in that category should contain that P407 property+value pair, I added those today via OpenRefine. Any ideas how to query a Commons category members (filenames) AND those files' P407's value ? Any pointer (key vocabulary to google) ? Yug (talk) 22:27, 24 August 2024 (UTC)Reply

Percentage of articles about women computer scientists, in Hebrew wikipedia

edit

I'm interested in the percentage of articles about women computer scientists in Hebrew Wikipedia.

For example if there're 20 articles about computer scientists in Hebrew, and 10 of them are about women, the result should be 50%.

Links: Hebrew category for female computer scientists | all computer scientists.

Note: there're nested categories (e.g. "American women computer scientists"), so I think that the query should count the articles recursively.

Thanks!

Galaranty (talk) 09:54, 25 August 2024 (UTC)Reply

Sorting a GROUP_CONCAT

edit

How can I get the following to return the keywords in alphabetical order?

SELECT DISTINCT ?item 
  (GROUP_CONCAT(DISTINCT ?keywordlist; SEPARATOR=", ") AS ?keywords) WHERE {

VALUES ?item {wd:Q1180981 wd:Q950970 wd:Q2543161}.

OPTIONAL {?item wdt:P31 ?k. ?k rdfs:label ?keywordlist. FILTER (LANG(?keywordlist) = "en")}

}
GROUP by ?item 
ORDER BY ?keywordlist
Try it!

Vicarage (talk) 09:16, 26 August 2024 (UTC)Reply

SPARQL doesn't support this. But if you have basic programming skills you can fix it by changing the downloaded data. You basically:
  • In the query group_concat() by using a sentinel value that is unlikely to appear in your data, for example "##".
  • In your script, split the string by the sentinel value to an array.
  • Sort the array.
  • Concatenate the array with your preferred separator an write the string back.
That will do it. I noticed you use Mediawiki on your site, that might be overkill if you don't need crowdsourcing. A LAMP stack with a framework that does caching (!), routing and templating will work just as well. After all getting data from a database endpoint is just a network request which fits nicely in a MVC design pattern. Infrastruktur (talk) 11:56, 26 August 2024 (UTC)Reply
Wow, something simple SPARQL can't do!!! My expounder.info sites use lots of mediawiki extensions which I've extended to make the whole setup really, really clever, and of course I can post-process the data, just hoping not to. Vicarage (talk) 12:29, 26 August 2024 (UTC)Reply

BTW, I know that wrapping the query in another select level can work

SELECT DISTINCT ?item  (GROUP_CONCAT(DISTINCT ?keywordlist; SEPARATOR=", ") AS ?keywords)
WHERE {
  {
  SELECT DISTINCT ?item ?keywordlist WHERE {    
    VALUES ?item {wd:Q1180981 wd:Q950970 wd:Q2543161}.
    {?item wdt:P31 ?k. ?k rdfs:label ?keywordlist. FILTER (LANG(?keywordlist) = "en")}
  }
  ORDER BY ?item ?keywordlist
  }
}
GROUP BY ?item
Try it!
This is definitely not portable to other query engines. The ordering from subqueries is not guaranteed to be preserved. It should say so somewhere in the specification but I don't feel like digging through it right now. Infrastruktur (talk) 21:40, 26 August 2024 (UTC)Reply

But my real query has WITH and subqueries for speed and ease of configuration, and wrapping does not work for a nested query. So this does not

SELECT DISTINCT ?item (GROUP_CONCAT(DISTINCT ?keywordlist; SEPARATOR=", ") AS ?keywords)
WHERE {
  {
  SELECT DISTINCT ?item ?keywordlist 
                       
  WITH {SELECT ?item ?keys WHERE {
    VALUES ?item {wd:Q1180981 wd:Q950970 wd:Q2543161}.
    VALUES ?keys {
      wdt:P31  # instance
    }
  }
  } AS %i
  WHERE {
    {INCLUDE %i}  
      {?item ?keys ?k. ?k rdfs:label ?keywordlist. FILTER (LANG(?keywordlist) = "en")}
  }
  ORDER BY ?item ?keywordlist
  }
}
GROUP BY ?item
Try it!

clarifying mul usage

edit

I'm still trying to get my head round mul. For example HNLMS Tonijn (Q2189292) is a ship with a Dutch prefix Hr.Ms., and a different prefix HNLMS everyone else in the world uses. So as well as the conventional labels, I've used mul and nl in its official name (P1448) to illustrate how mul would be the universal, nl the specific. How can I optimise this query to reduce the number of wikibase and FILTER commands, using all the techniques I can think of. Hopefully this can be the basis of an Example Query.

SELECT DISTINCT ?item ?itemLabel ?english ?native ?keyword WHERE {  
  SERVICE wikibase:label {bd:serviceParam wikibase:language "en,nl,mul"}
  
  VALUES ?item {wd:Q2189292}
  
  OPTIONAL {?item wdt:P31 ?k. ?k rdfs:label ?keyword. FILTER (LANG(?keyword) = "en")}
  
  SERVICE wikibase:label {bd:serviceParam wikibase:language "en,nl". ?item rdfs:label ?english}
  
  OPTIONAL {?item wdt:P1448 ?officialnl. FILTER (lang(?officialnl) = "nl")} # official name
  OPTIONAL {?item wdt:P1448 ?officialmul. FILTER (lang(?officialmul) = "mul")} # official name
  BIND(COALESCE(?officialnl,?officialmul) AS ?native)
}
Try it!

Vicarage (talk) 19:44, 27 August 2024 (UTC)Reply

@Vicarage: I'm not sure I understand what you are trying to do exactly. This query seems way to complex for what you want. The second line is useless and the variables ?itemLabel and ?english have the same content. And if you want the variable ?native why not just get the Dutch label? Right now, you are also getting the multilingual label just to discard it afterwards.
If I understand it right, I would just do:
SELECT DISTINCT ?item ?itemLabel ?native ?kLabel WHERE {    
  VALUES ?item {wd:Q2189292}
  
  OPTIONAL {?item wdt:P31 ?k }
  
  SERVICE wikibase:label {bd:serviceParam wikibase:language "en". }

  OPTIONAL {?item wdt:P1448 ?native. FILTER (lang(?native) = "nl")} # official name
}
Try it!
I'm not sure what you query the mul strings to not use them. Am I missing something?
Cheers, VIGNERON (talk) 11:45, 28 August 2024 (UTC)Reply
This is not a real world case, its trying to illustrate all the possible uses of language labels, so all the techniques can be covered. And I really didn't want find multiple entries with just the level of language coverage to illustrate a particular point Vicarage (talk) 12:20, 28 August 2024 (UTC)Reply
@Vicarage: even so, your query is still overly complicated. You never need to call the SERVICE wikibase:label twice in the same clause. And with "en,nl,mul" you are saying that you want the default label last (only if there is no English no Dutch label) and at the same time, you say that you want the English and Dutch titles... You also coalesce the native and multilingual title as native, which is strange ; multilingual is useful but it feels wrong to call it "native". Also, why mixing the label and title? can't you choose one or the other ? or one if not the other? You seems to overthink it... Maybe you could BIND the language instead? A real example would be useful to see what you're trying to actually solve. Cheers, VIGNERON (talk) 12:30, 28 August 2024 (UTC)Reply
We are at cross-porpoises. I have real world queries that use all these techniques individually, but not together.
Say I wanted
1) label in english, failing that mul
2) label in english, failing that mul, but with the phrase "Label=" prepended
3) official name, which may not be present, in english, failing that mul
4) if instances exist, their names in English "is a attack submarine, museum ship"
5) a string with all known official names "has 2 names, HNLMS Tonijn, Hr.Ms. Tonijn".
6) A string with all but (3), as in "has other names Hr.Ms. Tonijn"
And I'm very conscious that I'm very close to the API character count, and 60 second limit, so brevity and speed are key. Expect real query results to be a CSV file with 2000 results., one per line. I use multi-line json elsehwere, but this use case works much better with CSV
For what I do with the information, see HMS Victory Vicarage (talk) 13:10, 28 August 2024 (UTC)Reply

Filtering by enddate in a property

edit

I'm looking to create a query to get the actual ongoing index components of a stock index (IBEX35) (not only the full historical list). I filter companies who are part of IBEX35 and don't have and end date of being part. But query doesn't work and still shows me Q1493131 and Q944760 items, wich are not anymore components of the index. Any help on improving the query? Thanks in advance!

SELECT ?item ?itemLabel 

WHERE

{

?item wdt:P361 wd:Q938032. #Part of Ibex35 index

FILTER NOT EXISTS { ?item pq:P582 ?x }  #item has no P582 (end date) qualifier
  

SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 
}
Try it!

Kippelboy (talk) 10:01, 28 August 2024 (UTC)Reply

@Kippelboy: it's not working because the qualifier is not on the item but on the statement on the item. Here is the correct query :
SELECT ?item ?itemLabel WHERE {
  ?item p:P361 ?statement.
  ?statement ps:P361 wd:Q938032.
  FILTER(NOT EXISTS { ?statement pq:P582 ?x. }) #statement has no P582 (end date) qualifier
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!
Cheers, VIGNERON (talk) 11:52, 28 August 2024 (UTC)Reply
It works! Merci bien! :-)Kippelboy (talk) 13:14, 28 August 2024 (UTC)Reply