Wikidata:Request a query
Shortcuts: WD:RAQ, w.wiki/LX
Request a query ![]() 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 2025/05. |
![]() |
SpBot archives all sections tagged with {{Section resolved|1=~~~~}} after 2 days.
|
Weapons produced in EU query adjustment
[edit]At Wikidata:List of weapons produced by companies of EU countries there is
Warning: … is calling Template:Wikidata list with more than one value for the "(?country" parameter. Only the last value provided will be used.
That is because the query filters for all the countries of the European Union.
Previously, the query was filtering things via but I changed that at Special:Diff/2336617693 because checking that way may be slower performance and currently the table is not updated by the listeria bot possibly because of some performance issue and because Germany (Q183)part of (P361)European Union (Q458) was removed since it already has Germany (Q183)member of (P463)European Union (Q458) (I haven't checked if all the other EU countries also have that set).
It filters by the countries like so
FILTER((?country = wd:Q27)
|| (?country = wd:Q28)
|| (?country = wd:Q29)
[…]
How to filter differently? And if that is not enough to get the listeriabot to update the page what else needs to be done so that the page gets updated again? Btw, that tables shows many Wikidata items that have key data missing, in particular data about service retirement (P730) and related properties. Prototyperspective (talk) 17:50, 29 April 2025 (UTC)
- Hi, you can use
VALUES ?country { wd:Q27 wd:Q28 wd:Q29 ... }
to set specific values for the the?country
variable :). Samoasambia ✎ 11:21, 2 May 2025 (UTC)- Thanks, that worked. ListeriaBot still doesn't update the table without there being any error on its status page but maybe it takes a day or two. Prototyperspective (talk) 17:47, 2 May 2025 (UTC)
- The listeriabot still doesn't update the page. The bot status page nevertheless says OK. Earlier, another query was improved in a way that made it get updated by the listeriabot – can this query be improved anyhow to also enable it here? Made an issue about it here and that list linked there is working now somewhat and just not getting updated every week while the list of this thread doesn't work at all. Prototyperspective (talk) 15:01, 6 May 2025 (UTC)
Visualizing a King/President from a specific place in a specific time
[edit]Hello, I’m having some troubles understanding how to make things work with Wikidata.
My idea is: if a person over select Italy, in 1970, the name of the president of that time appears on a popup related to political information.
What I’m trying to understand is: before Italy was actually Italy, so before 1861, how do I query the item without hard coding the query like here.?
Same problem with Germany (and all the other countries). Here a query that goes back to 1871 for Germany, but I don’t know how to get the data before in a dynamic way.
Do you think is possible to query Wiki-data/pedia to obtain that specific information? Theoretically if the user select Rome, there should be some sort of continuity between the actual president of the republic, and roman emperors.
Ideally, it would have to work also for towns. But eventually I can distinguish between queries for nation-states and queries for towns
Thanks! Aoppo (talk) 12:42, 5 May 2025 (UTC)
- Hi @Aoppo:. In VALUES clause (You used it in Germany, last UNION) You can define sets of values
VALUES (?country ?leader_p ?leader_ps) {(wd:Q38 p:P6 ps:P6) (wd:Q172579 p:P6 ps:P6) (wd:Q172579 p:P35 ps:P35) (wd:Q172579 p:P1906 ps:P1906) }
(in this case three variables in each set), like this: https://w.wiki/D$t$. It's still kind of hardcoding, but with less code :) - Or You can code properties list with or
(P6 or P35)
like that:?country (p:P6|p:P35) ?statement.
. In this case in list of VALUES you need one variable with country list. (Also, if You don't want records without start date, You can querty for?statement pq:P580 ?start.
(without OPTIONAL clause), instead of adding FILTER later this variable later.) Something like that: https://w.wiki/D$vd. regards, Piastu (talk) 07:34, 6 May 2025 (UTC)- And if You want to get list of countries dynamically, instead of hardcoding it, You probably should to look at Property:P1365, Property:P1366, and use one of them in subselct to get list of countries. Like this: https://w.wiki/D$wj (maybe You need to modify
(p:P6|p:P35)
and add something to list). regards, Piastu (talk) 07:59, 6 May 2025 (UTC)
- And if You want to get list of countries dynamically, instead of hardcoding it, You probably should to look at Property:P1365, Property:P1366, and use one of them in subselct to get list of countries. Like this: https://w.wiki/D$wj (maybe You need to modify
Random article that exists in more than N languages
[edit]Hello, I am trying to build a query that works similarly to the "Random article" feature on Wikipedia, where it only gives articles of worldwide notability. Even using WP's random good article generator will often give articles similar to one of the many good articles about specific road structures, for instance. Articles should:
1. Exist in the English wikipedia
2. Exist in more than N wikipedias.
Thank you very much! Thepixelpest (talk) 09:57, 11 May 2025 (UTC)
- Here is a query which sort of achieve this, I am not sure I interpreted your request correctly, also this doesn't seem to run fast on WDSQ but run well on QLever, try it (it is also using their template feature)
- Try it!
SELECT ?item ?n ?count ?enlanguagelink WHERE { { SELECT ?item ?n ?enlanguagelink (COUNT(?wikipedias) AS ?count) WHERE { { SELECT ?i ?n WHERE { VALUES ?power { 10000 100000 1000000 10000000 100000000 } VALUES ?sample { 0 1 } BIND (FLOOR(RAND() * ?power + ?sample) AS ?n) . } } BIND (IRI(CONCAT("http://www.wikidata.org/entity/Q", STR(?n))) AS ?item) . ?sitelink schema:about ?item . ?sitelink schema:isPartOf ?wikipedias . FILTER (CONTAINS(STR(?wikipedias),"wikipedia.org")) ?enlanguagelink schema:about ?item . ?enlanguagelink schema:isPartOf <https://en.wikipedia.org/> } GROUP BY ?item ?n ?enlanguagelink } FILTER (?count > 10) . } ORDER BY substr(STR(?n),2,5) LIMIT 1
- I think I was more creative than rigorous in implementing the concept of "random", I guess there are many directions this can be improved, also if you want to increase the minimum number of sitelinks you may need to add more values to "?samples" to be sure to always get a results, but more samples also means longer query time. Ttmms (talk)
Person born or working within a 1st-level country division
[edit]I'm a trying to select artists born in or working in the province of Quebec, in Canada. The challenge is that values for place of birth (P19) and work location (P937) are stated at various levels of granularity: sometime, the value is stated at the municipality level; other times, the value is stated as the province level.
If I run my query at the municipal level, I get 3734 results:
SELECT DISTINCT ?vItem ?vItemLabel ?mun ?munLabel
WHERE {
VALUES ?live_performance {wd:Q713200 wd:Q3387717 wd:Q2490358 wd:Q639669} #performing artist, theatrical director, choreographer and/or musician
?mun wdt:P31/wdt:P279* wd:Q3327873 . #instance of municipality in Quebec
?vItem wdt:P31 wd:Q5 ; #Is a person
wdt:P19|wdt:P937 ?mun ; #born in or working in municipality in Quebec
(wdt:P106/(wdt:P279*)) ?live_performance . #has a live performance occupation
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,fr". }
}
However, I am missing 156 results from artists whose origin is stated at the provincial level:
SELECT DISTINCT ?vItem ?vItemLabel
WHERE {
VALUES ?live_performance {wd:Q713200 wd:Q3387717 wd:Q2490358 wd:Q639669} #performing artist, theatrical director, choreographer and/or musician
?vItem wdt:P31 wd:Q5 ; #Is a person
wdt:P19|wdt:P937 wd:Q176 ; #born in or working in the province of Quebec
(wdt:P106/(wdt:P279*)) ?live_performance . #has a live performance occupation
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,fr". }
}
How can I combine these two queries into a single query? Fjjulien (talk) 12:30, 14 May 2025 (UTC)
Wikidata Query Request
[edit]SELECT DISTINCT ?item ?itemLabel WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en". }
{
SELECT DISTINCT ?item WHERE {
?item p:P31 ?statement0.
?statement0 (ps:P31/(wdt:P279*)) wd:Q114079647.
?item p:P17 ?statement1.
?statement1 (ps:P17/(wdt:P279*)) wd:Q117.
?item p:P1001 ?statement2.
?statement2 (ps:P1001/(wdt:P279*)) wd:Q117.
?item p:P793 ?statement3.
?statement3 (ps:P793/(wdt:P279*)) wd:Q7099379.
?item p:P4884 ?statement4.
?statement4 (ps:P4884/(wdt:P279*)) wd:Q1513611.
?item p:P577 ?statement_5.
?statement_5 psv:P577 ?statementValue_5.
?statementValue_5 wikibase:timeValue ?P577_5.
?item p:P1031 ?statement6.
?statement6 (ps:P1031) _:anyValueP1031.
?item p:P5826 ?statement7.
?statement7 (ps:P5826/(wdt:P279*)) _:anyValueP5826.
?item p:P1594 ?statement8.
?statement8 (ps:P1594/(wdt:P279*)) _:anyValueP1594.
?item p:P1433 ?statement9.
?statement9 (ps:P1433/(wdt:P279*)) _:anyValueP1433.
}
LIMIT 1000
}
}
Hi everyone,
Hope you're doing well. My mentor @masssly referred me here, as you might have the best insights for my challenge.
We’re working on digitalizing all Supreme Court cases in Ghana, which are already on Wikidata, and developing an open-source web app using WDQS and the Wikidata API. The project will be hosted on WM Cloud or Toolforge to provide free access to past cases for law professionals and students.
However, we’re facing issues with our query. It is not displaying all the properties and values mentioned, and we would appreciate any guidance on refining it. I have attached the query above.
Looking forward to your thoughts.
Best,
Mustapha —Sunkanmi12✉️ 13:39, 15 May 2025 (UTC)
- Try it!
SELECT DISTINCT ?item ?itemLabel ?itemDescription ?date ?legal_citation ?majority_opinonLabel WHERE { ?item wdt:P577 ?date. ?item wdt:P1031 ?legal_citation. ?item wdt:P5826 ?majority_opinon. SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en". } { SELECT DISTINCT ?item WHERE { ?item p:P31 ?statement0. ?statement0 (ps:P31/(wdt:P279*)) wd:Q114079647. ?item p:P17 ?statement1. ?statement1 (ps:P17/(wdt:P279*)) wd:Q117. ?item p:P1001 ?statement2. ?statement2 (ps:P1001/(wdt:P279*)) wd:Q117. ?item p:P793 ?statement3. ?statement3 (ps:P793/(wdt:P279*)) wd:Q7099379. ?item p:P4884 ?statement4. ?statement4 (ps:P4884/(wdt:P279*)) wd:Q1513611. ?item p:P577 ?statement_5. ?statement_5 psv:P577 ?statementValue_5. ?statementValue_5 wikibase:timeValue ?P577_5. ?item p:P1031 ?statement6. ?statement6 (ps:P1031) _:anyValueP1031. ?item p:P5826 ?statement7. ?statement7 (ps:P5826/(wdt:P279*)) _:anyValueP5826. ?item p:P1594 ?statement8. ?statement8 (ps:P1594/(wdt:P279*)) _:anyValueP1594. ?item p:P1433 ?statement9. ?statement9 (ps:P1433/(wdt:P279*)) _:anyValueP1433. } LIMIT 1000 } } order by ?date
- @Sunkanmi12:: Hello, you have to add the things you want to show in the select clause. See my query for you. I add ?date ?legal_citation ?majority_opinon in line 3, 4 and 5. So you can use this terms in the select clause. --sk (talk) 20:11, 17 May 2025 (UTC)