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 2026/01. |
SpBot archives all sections tagged with {{Section resolved|1=~~~~}} after 2 days.
|
Query new items by origin site?
[edit]Is it possible to devise a query that can find recently created items with a wikilink to a specific wiki? I'm interested in Wikispecies in particular. Circeus (talk) 18:12, 4 December 2025 (UTC)
- Hi Circeus, it is possible. This query finds all items with Wikispecies sitelinks ordered by the highest QID i.e. most recently created. I set the cutoff at Q137000000 but you can change that.
- Try it!
SELECT ?item ?sitelink WHERE { # Get sitelinks ?sitelink schema:about ?item ; schema:isPartOf <https://species.wikimedia.org/> . # Extract numeric part of QID BIND(xsd:integer(STRAFTER(STR(?item), "Q")) AS ?qidNumber) # Filter with QID cutoff FILTER(?qidNumber > 137000000) } ORDER BY DESC(?qidNumber)
- –Samoasambia ✎ 18:44, 7 December 2025 (UTC)
- I can't believe I forgot to say it, but thank you so much. It's been super helpful to find items that aren't obscure database imports. Circeus (talk) 05:41, 22 December 2025 (UTC)
Improving a query
[edit]Hi, I have the following query that isn't working as I would expect
SELECT distinct ?item ?itemLabel ?authorLabel ?awardLabel WHERE {
VALUES ?genre { wd:Q5528690 wd:Q3139891 }
VALUES ?awards { wd:Q160082 wd:Q833633 wd:Q18884 wd:Q3873144 wd:Q2052291 }
?item wdt:P136 ?genre;
wdt:P166 ?award;
wdt:P50 ?author.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
I'm trying to find books which have won one of those awards, but I'm also getting books which have won other awards? Is there a better way to do this? Carlinmack (talk) 17:36, 13 December 2025 (UTC)
- Variable names for containing
awardsis not consistent. In the first line you used?awardLabelin the third line you used?awards, and in the sixth you usedaward. I revised the query: - Try it!
SELECT distinct ?item ?itemLabel ?authorLabel ?awardsLabel WHERE { VALUES ?genre { wd:Q5528690 wd:Q3139891 } VALUES ?awards { wd:Q160082 wd:Q833633 wd:Q18884 wd:Q3873144 wd:Q2052291 } ?item wdt:P136 ?genre; wdt:P166 ?awards; wdt:P50 ?author. SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } }
- —Yamato Shiya大和 士也 (Talk • Contribs) 16:03, 14 December 2025 (UTC)
- Ah thank you! silly mistake Carlinmack (talk) 16:59, 14 December 2025 (UTC)
Pinyin qualifier to Chinese name
[edit]I would like to find out, which Chinese speaking people (badminton players) have a Chinese native name, but not yet a Hanyu Pinyin transliteration. Some hopefully helpful properties: wdt:P106 wd:Q13141064; wdt:P103 wd:Q7850; wdt:P1559; wdt:P1721. Example: Q137300399 has a Hanyu Pinyin transliteration. But on which items is this transliteration missing? Florentyna (talk) 20:05, 18 December 2025 (UTC)
- Here's a query for that: https://w.wiki/H68B . This just looks for missing transliteration qualifier. If you want any tweaks let me know. Infrastruktur (talk) 14:46, 20 December 2025 (UTC)
Sort by P2046 not working
[edit]I made the folowing query that is translated in the wikipedia page: pt:Usuário:GualdimG/Testes/Listas/Freguesias
1) I intend to sort it by P2046 (4th column), but is not working. 2) The date of the Census (P585), does not appear in the 6th column
SELECT ?item ?area ?area_ WHERE {
?item wdt:P31 wd:Q1131296.
?item wdt:P17 wd:Q45 .
optional { ?item p:P2046 [ psn:P2046/wikibase:quantityAmount ?area ] }
} order by desc(?area)
Would you help me improve what is incorrect? Thank you. GualdimG (talk) 11:51, 20 December 2025 (UTC)
- I removed the Wikidata table code from here and left only the SPARQL because ListeriaBot will add the full table if the Wikidata table template is kept here. You can have a look at pt:Usuário:GualdimG/Testes/Listas/Freguesias for the full code. Samoasambia ✎ 12:44, 20 December 2025 (UTC)
- Here is a query that I think does the trick : . To adapt it for Wikidata list you remove the "sort" parameter, as the query does it itself now, and you take the column name like "?pop" instead of the property number in the "column" parameter. author TomT0m / talk page 12:47, 20 December 2025 (UTC)Try it!
SELECT ?item ?area ?area_ ?pop ?census_date WHERE { ?item wdt:P31 wd:Q1131296. ?item wdt:P17 wd:Q45 . ?item p:P1082 ?pop_st . ?pop_st ps:P1082 ?pop . optional { ?pop_st pq:P585 ?census_date } ?pop_st a wikibase:BestRank . optional { ?item p:P2046 [ psn:P2046/wikibase:quantityAmount ?area ] } }
- Thank you, Samoasambia and TomT0m, for you work and answer. I copyed the script you had written above to the Wikipedia article pt:Usuário:GualdimG/Testes/Listas/Freguesias, but seems that it is not yet working, I mean the sort of values by the value P2046. Wouldn't you mind to analyse it again. You can obviously make changes in the article. Thank you. GualdimG (talk) 16:47, 20 December 2025 (UTC)
- I copyed the revision of this page at 12h20min de 20 de dezembro de 2025 by TomT0m to "Usuário:GualdimG/Testes/Listas/Freguesias por area" and it work, the sort is made by the area, 4th column. Thank you. GualdimG (talk) 17:11, 20 December 2025 (UTC)
- Thank you, Samoasambia and TomT0m, for you work and answer. I copyed the script you had written above to the Wikipedia article pt:Usuário:GualdimG/Testes/Listas/Freguesias, but seems that it is not yet working, I mean the sort of values by the value P2046. Wouldn't you mind to analyse it again. You can obviously make changes in the article. Thank you. GualdimG (talk) 16:47, 20 December 2025 (UTC)
Peak population year
[edit]Hello! I have a quite complex query idea. I have uploaded the population series from 1900 to 2025 in all the municipalities of Navarre (Q4018). Would it be possible to query which year was the highest population for each of the municipalities (municipality of Spain (Q2074737)). Thanks! Theklan (talk) 10:58, 26 December 2025 (UTC)
- Hi, looking at the amount of municipalities Spain had in Wikidata (around 6200) I assume you want to find them per province. Its really complex because you have to process not only statements, but level 1 down to the qualifiers. I scratched my head, asking around (including asking You-Know-Who), after several timeouts, this is what I am able to compose:
- Note: this is only for municipalities in Navarre (Q4018). Ordered by municipality label. I checked I see no duplicate in each municipality. If you found them then perhaps its same value for different year.
- Try it!
SELECT ?municipality ?municipalityLabel ?population ?year WHERE { { SELECT ?municipality ?population ?year WHERE { ?municipality wdt:P31 wd:Q2074737 ; wdt:P131 wd:Q4018 . ?municipality p:P1082 ?st . ?st ps:P1082 ?population ; pq:P585 ?year . { SELECT ?municipality (MAX(?pop2) AS ?maxPop) WHERE { ?municipality wdt:P31 wd:Q2074737 ; wdt:P131 wd:Q4018 . ?municipality p:P1082 ?st2 . ?st2 ps:P1082 ?pop2 . } GROUP BY ?municipality } FILTER(?population = ?maxPop) } } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } ORDER BY ?municipalityLabel
- There you go. —Yamato Shiya大和 士也 (Talk • Contribs) 11:51, 28 December 2025 (UTC)
- I also asked that friend you mention, but it gave nonsense, and then another worse approach. But yours work... so thank you very much! Theklan (talk) 15:37, 28 December 2025 (UTC)
New query - with errors
[edit]Happy New Year! I tried to make a query at Usuário:GualdimG/Testes/Listas/autor 1955. (pt wikipedia) The goal is to list the Portuguese authors that died in 1955. Their works enter in Public Domain. The query is not working. Something is wrong. Would you help me to fix it? You can make changes in the refered page. Thank you. GualdimG (talk) 14:21, 1 January 2026 (UTC)
Records with no source for date of birth
[edit]Hello and Happy New Year! Please can someone help with a query to produce a list of Olympians (using Olympedia people ID - P8286) who have a DOB with no source? I've tried but with little success. For example, this record has a P8286 ID and has a flag for zero references on their DOB - https://www.wikidata.org/wiki/Q29064871
Thank you. HelplessChild (talk) 19:16, 1 January 2026 (UTC)
- I think this query does what you want:
- It times out on the regular query service, so try QLever. Ainali (talk) 22:04, 1 January 2026 (UTC)
- Excellent! Thank you. I've included a line to pick out a year at a time, which helps a lot with the runtime.
- Thanks again. HelplessChild (talk) 12:43, 2 January 2026 (UTC)
.jpg/250px-Getting_Away_From_It_All_(15015598224).jpg)
