Shortcuts: WD:RAQ, w.wiki/LX
Wikidata:Request a query
Request a query 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 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/07. |
Only wikipedia sitelinks
[edit]Hi. Would it be possible to change this query to only take into account wikipedia sitelinks and not wikisource, commons, etc. ones? Thanks in advance, Paucabot (talk) 12:53, 12 July 2024 (UTC)
- In what way? If you simply want to list entities that have at least one wikipedia sitelink you can do that by adding a semi-join: https://w.wiki/Aena . But if you want the count of sitelinks only to wikipedia that will require a lot more work. I might be too lazy to write the latter. Infrastruktur (talk) 12:35, 13 July 2024 (UTC)
- I think I'm asking for the latter. Paucabot (talk) 20:29, 13 July 2024 (UTC)
Conflation query barely returns any results
[edit]Not sure why this query is returning so few results. It only returns 29 items, but I expected it to return a lot more. Twin Star Exorcists (Q17228961) is one item that has both conflation (Q14946528) and anime television series (Q63952888), so not sure why it isn't part of the results too. Any help would be really appreciated!
- Finnius00 (talk) 22:36, 12 July 2024 (UTC)Try it!
SELECT ?item ?itemLabel (GROUP_CONCAT(?instanceOfLabel; SEPARATOR=", ") AS ?instanceOfValues) WHERE { ?item wdt:P31 wd:Q14946528. ?item wdt:P31 ?type. VALUES ?type { wd:Q63952888 wd:Q74262765 } ?item wdt:P31 ?instanceOf. ?instanceOf rdfs:label ?instanceOfLabel. FILTER(LANG(?instanceOfLabel) = "en") SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } GROUP BY ?item ?itemLabel
List of notable people whose last name is a common English noun
[edit]I’m working on a word game and was looking for a list of “notable people” whose names are also nouns. I tried doing the query for it but it seems to be way over my limited Wikidata/SPARQL knowledge.
Here’s what I have so far:
- Try it!
# list of nouns SELECT ?lexeme ?lexemeLabel ?lexical_category ?lexical_categoryLabel WITH { SELECT ?lexeme ?lexemeLabel ?lexical_category WHERE { ?lexeme a ontolex:LexicalEntry ; dct:language wd:Q1860 ; wikibase:lemma ?lexemeLabel . OPTIONAL { ?lexeme wikibase:lexicalCategory ?lexical_category . } } LIMIT 10000 } AS %results WHERE { INCLUDE %results OPTIONAL { ?lexical_category rdfs:label ?lexical_categoryLabel . FILTER (LANG(?lexical_categoryLabel) = "en") } }
and
- FiP (talk) 13:01, 19 July 2024 (UTC)Try it!
# “celebrities” SELECT DISTINCT ?lastNameLabel WHERE { # Identify celebrities by their occupation ?celebrity wdt:P106 ?occupation; wdt:P734 ?lastName. # Filter for notable occupations VALUES ?occupation { wd:Q33999 # actor wd:Q639669 # musician wd:Q483501 # artist wd:Q36180 # writer wd:Q82955 # politician wd:Q2066131 # athlete wd:Q211236 # celebrity } # Get labels for readability SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } LIMIT 1000
SPARQL query to sum number of seats of lower houses
[edit]Hi all, I am a bit new to Wikidata, and to SPARQL even more!
I created Lower houses of the European Union (Q127603696) to specifically list all relevant lower houses in the EU (and the matching Upper houses of the European Union (Q127603941)). I am now trying to find a way to sum the number of seats (P1342) of each of these lower houses, to come up with a single number that I can use for composition boxes, such as in the infobox of this page European People's Party. This would avoid having to recalculate the total number of seats of lower/upper houses whenever one changes.
I tried my luck with the Wikidata_talk:SPARQL_tutorial and the Wikidata Query Service, and even asked on the live chat, but was not able to find the solution, which I believe should not be too complicated. Eventually, I posted on Wikidata:Project chat and a kind soul pointed to this page.
A side question would be: how can I then use this query as a figure on Wikipedia (such as for the infobox above)?
Thanks in advance! Julius Schwarz (talk) 14:55, 19 July 2024 (UTC)
DISTINCT for character strings
[edit]For
SELECT DISTINCT ?item
(GROUP_CONCAT(DISTINCT ?namelist; SEPARATOR = ", ") AS ?names)
(COUNT (DISTINCT ?namelist) AS ?count) WHERE {
VALUES ?item {wd:Q2420611}
OPTIONAL
{
{?item wdt:P2561 ?namelist} # name
UNION {?item wdt:P1448 ?namelist} # official name
UNION {?item wdt:P1449 ?namelist} # nickname
UNION {?item wdt:P879 ?namelist} # pennant
UNION {?item skos:altLabel ?namelist. FILTER(LANG(?namelist) = "en")} # aliases
}
}
GROUP BY ?item
I don't want HMS Colossus to be repeated in the output. Vicarage (talk) 12:37, 25 July 2024 (UTC)
- Change lines 2 and 3 to:
(GROUP_CONCAT(DISTINCT STR(?namelist); SEPARATOR = ", ") AS ?names)
(COUNT (DISTINCT STR(?namelist)) AS ?count) WHERE {