Wikidata:Request a query

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 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 2023/09.


average amount of values of a property Edit

for instance: some items have 10 values for Fandom article ID (P6262). most items, probably have one value. But how many values does Fandom article ID (P6262) have on average? novalue and somevalue statements should not be counted. thanks in advance 😃 – Shisma (talk) 09:34, 26 August 2023 (UTC)Reply[reply]

Looks like you don't get novalues unless you specifically ask for them, so it's sufficient to filter away somevalues. Here is average: https://w.wiki/7LGS, and distribution: https://w.wiki/7LGc. Infrastruktur (talk) 20:23, 26 August 2023 (UTC)Reply[reply]
@Infrastruktur thank you. that looks great! – Shisma (talk) 19:12, 4 September 2023 (UTC)Reply[reply]

If Possible show Multiple places in Map View Edit

Hi, I want view like church building (Q16970), mosque (Q32815) and Hindu temple (Q842402) in Map view. Sriveenkat (talk) 14:32, 29 August 2023 (UTC)Reply[reply]

@Sriveenkat: My solution:
SELECT ?item ?itemLabel ?layer ?layerLabel ?coord WHERE {
  VALUES ?layer {wd:Q16970 wd:Q32815 wd:Q842402}
  ?item wdt:P17 wd:Q219. # Bulgaria. Change country as needed.
  ?item wdt:P31 ?layer.
  ?item wdt:P625 ?coord.
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
}
}
#defaultView:Map
Try it!
I had to restrict the query to just one country because there are over 200,000 church building (Q16970), mosque (Q32815) and Hindu temple (Q842402) in the world and that is too much to get labels without timing out.
Please notice that there are items in subclasses of church building (Q16970), mosque (Q32815) and Hindu temple (Q842402) (for example, hermitages, basilicas or cathedrals) that aren't shown in this query.
Does this query work for you?--Pere prlpz (talk) 20:50, 31 August 2023 (UTC)Reply[reply]
@Pere prlpz Thankyou works good 💯. If possible we can define any colours? Thanks for your support Sriveenkat (talk) 01:14, 1 September 2023 (UTC)Reply[reply]
@Sriveenkat: As far as I know you can use any variable to define colours (you just need to name that variable as "layer") but you can't pick which colours to use. In my experience, the palette is selected at random every time the query is executed. You can't even get a consistent palette in a given query (e.g. you won't get always the same colours with the same meaning for that query).
If you want more control over the results you may want to try mw:Help:Extension:Kartographer/Getting started, which I think now can accept a query as external data, but I've never used it and the query thing is a very new feature that might not be well documented.--Pere prlpz (talk) 09:10, 1 September 2023 (UTC)Reply[reply]
You can set the colour using the ?rgb variable and specifying the colour using hex codes; add ?rgb to the SELECT statement and define the colours in the VALUES statement like so:
SELECT ?item ?itemLabel ?layer ?layerLabel ?coord ?rgb WHERE {
VALUES (?layer ?rgb) { (wd:Q16970 "ff0000") (wd:Q32815 "00ff00") (wd:Q842402 "0000ff" )} Piecesofuk (talk) 15:19, 1 September 2023 (UTC)Reply[reply]
@Piecesofuk Thanks Sriveenkat (talk) 00:16, 16 September 2023 (UTC)Reply[reply]

digital preservation Edit

Maggie Masenya Magretiah (talk) 10:13, 4 September 2023 (UTC)Reply[reply]

@Magretiah: What's the question?--Pere prlpz (talk) 16:00, 16 September 2023 (UTC)Reply[reply]

P276 = only countries Edit

Hello, I'd like a list of items having P276 = a country (not a town, a precise place, etc) and having no P17. Thanks Bouzinac💬✒️💛 05:20, 6 September 2023 (UTC)Reply[reply]

@Bouzinac: If I'm not missing anything, it seems that there are no items with location (P276) pointing to a sovereign state (Q3624078) or subclass of it:

SELECT DISTINCT ?item ?itemLabel ?country ?countryLabel
 
WHERE
{
  ?item wdt:P276 ?country.
  ?country wdt:P31/wdt:P279? wd:Q3624078.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,ca". } 
}
Try it!

--Pere prlpz (talk) 15:58, 16 September 2023 (UTC)Reply[reply]

@Bouzinac: Sorry, my query had a fatal typo, now fixed, that yielded no results. Now it finds over 21000 results. I had to restrict the subclass tree to avoid timing out, although other optimisations should be possible.--Pere prlpz (talk) 19:26, 17 September 2023 (UTC)Reply[reply]

Hello, how about this (not very good) query https://w.wiki/7UDs . I wished this query opens more countries and restrains to any physical stuff (house, road, etc) but not concepts (war, idea, etc) Bouzinac💬✒️💛 16:27, 16 September 2023 (UTC)Reply[reply]

After having worked with lists of placenames in Wikipedia, I can tell you that restraining to "any physical stuff" is very difficult, because the trees for most of physical stuff are too large and often mixed with things that aren't physical stuff.
A possible workaround is to select items with coordinates, and/or filter out (with MINUS) the items you don't want.--Pere prlpz (talk) 19:30, 17 September 2023 (UTC)Reply[reply]

Items sorted by number of edits/revisions Edit

Hey!

so far, if I wanted to sort English Wikipedia articles by number of edits/revisions, I have had to look at either their page information or XTools or call the API with something like https://en.wikipedia.org/w/rest.php/v1/page/foo/history/counts/edits - in all of these cases I have had to look at the stats separately for each article because none seems to provide a comparison function.

I would love to have a single SPARQL query that lets me rank a few given enwiki articles (which I can obviously provide as Wikidata objects) by number of edits, which I assume to be a good metric for public interest in the concept behind the article. I myself don't understand the mwapi service and its many functions well enough to come up with a solution myself.

I know ranking articles by number of edits didn't use to be possible but I thought it couldn't hurt to ask whether it is now.

Best, Weasel (talk) 22:29, 7 September 2023 (UTC)Reply[reply]

@Weasel: I don't know if a query could access that information (I don't think so) but I don't think that Wikidata can help you here, because the information you need is all in Wikipedia, not Wikidata.
In fact English Wikipedia has an special page with what you want: en:Special:MostRevisions. Wikipedia:Statistics has links to related pages.--Pere prlpz (talk) 15:50, 16 September 2023 (UTC)Reply[reply]

Missing Tamil Descriptions wikpedia article available in the Tamil Wikipedia Edit

I want to add missing American actress Tamil descriptions for Available Tamil Wikipedia Articles. Thank you Sriveenkat (talk) 07:25, 11 September 2023 (UTC)Reply[reply]

Do you need a query of all American actresses with Tamil Wikipedia article without Tamil language description to find those articles and write descriptions by hand? Or do you want to learn how to automatically put the same Tamil description (e.g. "American actress" in Tamil) in all those items?--Pere prlpz (talk) 15:41, 16 September 2023 (UTC)Reply[reply]
@Pere prlpz I want put automatically put the same tamil description Example: "American Actress" translate "அமெரிக்க நடிகை" Thanks. Sriveenkat (talk) 03:44, 17 September 2023 (UTC)Reply[reply]
@Sriveenkat: PetScan (with SPARQL) can add properties but I think it can't add descriptions. Therefore I suggest:
  • Using a query to get all American actresses, with their Tamil description if it exists, and export results in a csv file (or any other format).
  • Import the data to an spreadsheet (like Excel or LibreCalc), filter out actresses with Tamil description and create QuickStatements instructions to add the Tamil description to the remaining ones. I would do this part using R or Python instead of Excel because I'm used to them and have scripts for similar jobs, but a spreadsheet can have the work done quite easily.
  • Paste the instructions to QuickStatements and run them.
I wouldn't restrict that to only actresses with article in Tamil Wikipedia because it's not a lot of additional work to upload some thousands of descriptions instead of some hundreds.
Just in case it may be useful, I leave here a query to get American actresses and their Tamil description.--Pere prlpz (talk) 17:58, 17 September 2023 (UTC)Reply[reply]
@Pere prlpz Thanks. I am very much obliged to you. Thanks again Sriveenkat (talk) 18:42, 17 September 2023 (UTC)Reply[reply]
@Pere prlpz Thank you so much. Now America actresses Adding Tamil Description Adding is   Done. It's possible to create a tutorial video or article about Adding labels and descriptions using Spreadsheets and QuickStatements as your workflow? That's really useful for Beginners. Thanks again Sriveenkat (talk) 03:45, 19 September 2023 (UTC)Reply[reply]
@Sriveenkat: I think I've never done that with Excel because I usually use R or sometimes Python for tasks like this one. If Excel worked for you, you can do the tutorial. However, there are already pages and videos on how to use QuiciStatements with Excel or Google Spreadsheets. Googling for it yields a handful of interesting resources.--Pere prlpz (talk) 08:36, 19 September 2023 (UTC)Reply[reply]
SELECT ?item ?nameen ?nameta ?descr
WHERE {
  ?item wdt:P31 wd:Q5.
  ?item wdt:P27 wd:Q30.
  ?item wdt:P106/wdt:P297* wd:Q33999.
  ?item wdt:P21 wd:Q6581072.
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
  ?item rdfs:label ?nameen.
}
SERVICE wikibase:label {
bd:serviceParam wikibase:language "ta" .
  ?item rdfs:label ?nameta.
  ?item schema:description ?descr.
}
}
Try it!

Find items with a particular property with sitelink to Wikipedia Edit

What is the simplest way of finding all items with a particular property (with any value except novalue) that also have a sitelink to the English language Wikipedia. Thanks. — Martin (MSGJ · talk) 15:22, 11 September 2023 (UTC)Reply[reply]

@MSGJ: Seems to be as below. I use P718 as the example since I know there are <novalue> statements for this ... by & large I've convinced myself that items with (only) <novalue> P718 statements are not being picked up.
SELECT distinct ?item 
WHERE 
{
  ?item wdt:P718 [].                            # The property of interest
  ?article schema:about ?item ;                 # has a sitelink
  schema:isPartOf <https://en.wikipedia.org/> . # sitelink is to EN wikipedia
}
Try it!
--Tagishsimon (talk) 10:07, 12 September 2023 (UTC)Reply[reply]
Thank you — Martin (MSGJ · talk) 13:29, 13 September 2023 (UTC)Reply[reply]
When running with a well-used property like Library of Congress authority ID (P244) the query is timing out. Is there anything that can be done to prevent this?
SELECT distinct ?item 
WHERE 
{
  ?item wdt:P244 [].                            # The property of interest
  ?article schema:about ?item ;                 # has a sitelink
  schema:isPartOf <https://en.wikipedia.org/> . # sitelink is to EN wikipedia
}
Try it!
— Martin (MSGJ · talk) 18:59, 13 September 2023 (UTC)Reply[reply]
@MSGJ: My inclination would be to slice the P244 dataset and look at batches of ~200k or somesuch amount. Increment the offset to get the next batch. There are 1.5 million uses of P244.
SELECT distinct ?item 
WHERE 
{
  
   SERVICE bd:slice {
      ?item wdt:P244 []. 
    bd:serviceParam bd:slice.offset 0 . # Start at item number (not to be confused with QID)
    bd:serviceParam bd:slice.limit 200000 . # List this many items
  }  
                             # The property of interest
  ?article schema:about ?item ;                 # has a sitelink
  schema:isPartOf <https://en.wikipedia.org/> . # sitelink is to EN wikipedia
}
Try it!
--Tagishsimon (talk) 17:38, 15 September 2023 (UTC)Reply[reply]

Create a map pinpointing abandoned buildings (Q106765618) in São Paulo city (Q174) Edit

I tried creating this query a few weeks ago but it has been a while since I created my own queries on Wikidata. Would love some help, thanks! Tet (talk) 18:04, 12 September 2023 (UTC)Reply[reply]

I am not entirely sure if former building or structure (Q96084375) is better for search queries! Tet (talk) 18:10, 12 September 2023 (UTC)Reply[reply]

@Tet: Here are both, in separate queries but worldwide:

#defaultView:Map
SELECT DISTINCT ?item ?itemLabel ?coord
 
WHERE
{
    ?item wdt:P31 wd:Q106765618.
      ?item wdt:P625 ?coord.
        SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],pt,en". } 
}
Try it!
#defaultView:Map
SELECT DISTINCT ?item ?itemLabel ?coord
 
WHERE
{
    ?item wdt:P31 wd:Q96084375.
      ?item wdt:P625 ?coord.
        SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],pt,en". } 
}
Try it!

You can see that there aren't any abandoned building or structure (Q106765618) or former building or structure (Q96084375) in Sao Paulo, which can mean that:

  • All buildings in Sao Paulo are in perfect working order and none of them is abandoned.
  • Or that nobody has updated the abandoned state of the buildings.
  • Or that the status has been informed using other properties like state of conservation (P5816).
  • Or that abandoned buildings in Sao Paulo lack coordinates.

I suggest doing first some research by looking at items of buildings in Sao Paulo that you may know are abandoned.--Pere prlpz (talk) 15:37, 16 September 2023 (UTC)Reply[reply]

Looking for candidate duplicate items Edit

So, for example, Pak Dong-uk (Q79404675) has Olympedia people ID (P8286) = 56280, and links to one Wiki article (en.wp). It seems reasonable that any other Wikidata items with Olympedia people ID (P8286) = 56280 would be candidates for merging with Pak Dong-uk (Q79404675). So a warm-up query here would be to return Wikidata items with Olympedia people ID (P8286) = 56280 and with at least one Wikimedia link, so long as there are at least two such items. If there's only one (i.e. Pak Dong-uk (Q79404675) itself), return nothing.

More generally, Olympedia people ID (P8286) itself has property constraint (P2302): distinct-values constraint (Q21502410), so it is not the only property that signifies a unique ID. It seems reasonable that all duplicate Wikidata items with the same value for a distinct-values constraint (Q21502410)-property would be candidates for merging.

The full query I am thinking of is to return all sets of multiple (>1) Wikidata Q-items, where each item has the same value for at least one P-property that itself has a distinct values constraint. I.e. all sets of multiple Q-items for athletes with the same Olympic ID, of all films with the same IMDb ID (P345), etc.

And finally, all the stuff above except for exceptions (exception to constraint (P2303)) to the P-value in question's distinct values constraint. E.g. see property constraints of IMDb ID (P345), which says among other things that Shiva (Q7499225) and Siva (Q7532265) are allowed to have the same IMDb ID (P345). So those two should be excluded from the results. It Is Me Here (talk) 16:11, 15 September 2023 (UTC)Reply[reply]

@It Is Me Here: Property talk:P8286 contains a template for each constrain with a link to a constraint violation report and to a couple of SPARQL queries for that constraint. I think those are the queries you need.
Btw., now the only violation of unique value constraint are the article and the category for the same athlete and we don't seem to be going to find duplicates using this property, although it may work with other properties.--Pere prlpz (talk) 15:26, 16 September 2023 (UTC)Reply[reply]

Name for a URL link Edit

Hi! I need your help. I get this query with a link to a URL of Tabakalera. How could I replace the URL with a linking term? In html language is something like "<a href="document.html">Term</a> Thank you

#defaultView:Map
SELECT DISTINCT ?item ?itemLabel ?TabakaleraLabel ?TabakaleraURL ?lugar ?coord
 
WHERE
{
    ?item wdt:P31 wd:Q5.
    ?item wdt:P1344 wd:Q9081343.
    ?item wdt:P10069  ?Tabakalera.
      ?item wdt:P19 ?lugar. 
      ?lugar wdt:P625 ?coord.

  
 OPTIONAL{?item wdt:P569 ?birthdate .} # P569 : Date de naissance
   BIND(year(?birthdate) as ?year)
  FILTER(?year > 1800)
  wd:P10069 wdt:P1630 ?formatterurl .
 BIND(IRI(REPLACE(?Tabakalera, '^(.+)$', ?formatterurl)) AS ?TabakaleraURL).


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

Lmerice (talk) 19:57, 15 September 2023 (UTC)Reply[reply]

Get all parent classes from a list of classes Edit

I currently have a query that gets all classes an item has:

SELECT DISTINCT ?class ?classLabel WHERE {
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
	wd:${instance} wdt:P31/wdt:P279* ?class.
}
Try it!

I'd like to skip the instance of (P31) part and query a list of classes instead. For example, I want to get all parent classes of television character (Q15773317), comics character (Q1114461) and literary character (Q3658341) in a single query. How do I do that? – Shisma (talk) 11:30, 16 September 2023 (UTC)Reply[reply]

And all classes should be in the ?class variable. The classes requested as well as those in the query. –Shisma (talk) 11:34, 16 September 2023 (UTC)Reply[reply]

SELECT DISTINCT ?class ?classLabel WHERE {
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
	{ wd:Q3658341 wdt:P279* ?class. }
    UNION 
    { BIND (wd:Q3658341 as ?class) }
    UNION
	{ wd:Q15773317 wdt:P279* ?class. }
    UNION 
    { BIND (wd:Q15773317 as ?class) }
    UNION
	{ wd:Q3658341 wdt:P279* ?class. }
    UNION 
    { BIND (wd:Q3658341 as ?class) }
}
Try it!

Is this it, or is there a better way to do this –Shisma (talk) 11:38, 16 September 2023 (UTC)Reply[reply]

You just need to use VALUES instead of repeating the same query for each value:
SELECT DISTINCT ?class ?classLabel WHERE {
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  VALUES ?targetClass {wd:Q3658341 wd:Q15773317 wd:Q365834}
	?targetClass wdt:P279* ?class. 
}
Try it!
Does that work for you?--Pere prlpz (talk) 15:10, 16 September 2023 (UTC)Reply[reply]
unfortunately, ?class should also include literary character (Q3658341), television character (Q15773317) and Q365834.– Shisma (talk) 15:36, 16 September 2023 (UTC)Reply[reply]
@Shisma: You just need to add as many classes as you want in the "VALUES ?targetClass {wd:Q3658341 wd:Q15773317 wd:Q365834}" line. Now it works with three classes but it would work fine with a handful more.--Pere prlpz (talk) 08:46, 19 September 2023 (UTC)Reply[reply]

sets of mythological Greek characters Edit

Hi all, I want to clean up our items which are supposed to be instance of (P31)set of mythological Greek characters (Q26214208).

There are a lot of items not properly classified. We can find them with a query which lists all Wikidata items that

  1. do not have the statement instance of (P31)set of mythological Greek characters (Q26214208) AND
  2. have a sitelink to any page from w:en:Category:Set index articles on Greek mythology

I couldn't manage myself using the Query Builder. Can you help?

Thanks, and have great day, Jonathan Groß (talk) 18:15, 17 September 2023 (UTC)Reply[reply]

This is a start, but not exactly what I wanted: https://w.wiki/7Udd Jonathan Groß (talk) 18:52, 17 September 2023 (UTC)Reply[reply]

@Jonathan Groß:: Dealing with categories with a query is possible, but I think it's easier to use PetScan, which deals primarily with categories and can combine them with queries.--Pere prlpz (talk) 19:08, 17 September 2023 (UTC)Reply[reply]
I've now tried Petscan, but I couldn't do it. Problem is, I want to combine statements from two different wikis. Maybe I'll just go through the category one by one ... Jonathan Groß (talk) 06:10, 18 September 2023 (UTC)Reply[reply]
@Jonathan Groß:: Your question only mentions English Wikipedia. If you mean English Wikipedia and Wikidata, PetScan can deal with that. If you mean two different Wikipedias, you can use PetScant to download data from each one and combine them using any program that can manage data. I would do it using R but Excel or any Spreadsheet can work.--Pere prlpz (talk) 08:42, 19 September 2023 (UTC)Reply[reply]
@Pere prlpz:: I want to combine info from Wikidata and enwiki only, as stated above, but I can't figure out how to make Petscan do that. To me it seems I have to choose between headers ("Categories", "Page properties" etc.) but can only run a query from one of those headers, not from many put together with different properties. Or am I missing something? Could you perhaps show me how to do it? Jonathan Groß (talk) 09:05, 19 September 2023 (UTC)Reply[reply]
@Jonathan Groß:: You can put conditions under all of those headers at the same time. To combine Wikipedia with Wikidata you can use simple options (like items having or not having some properties) or you can use a query in the "Other sources" tab.
For example, here are saxophonists (according to Wikidata) whose article in Catalan Wikipedia is not in category:Saxofonistes nor its subcategories combining categories in cawiki with a query.--Pere prlpz (talk) 10:11, 19 September 2023 (UTC)Reply[reply]

list of all rappers Edit

I'm trying to do a basic query that returns all entities where occupation is rapper (wdt:P106 wd:Q2252262). I get back almost 8000 results but I noticed that one entry (for example) -- Q-Tip (Q42025) -- is missing, despite the fact that rapper / Q2252262 is indeed one of the listed occupations on his wikidata page. Query is as follows:

SELECT DISTINCT ?rapper ?rapperLabel WHERE {
  {
    ?rapper wdt:P106 wd:Q2252262;
      rdfs:label ?rapperLabel.
    FILTER((LANG(?rapperLabel)) = "en")
  }
}
ORDER BY (?rapperLabel)
Try it!

Not sure why his page wouldn't be included in the results, or how to modify the query to ensure that it is. Any help would be greatly appreciated. Slieb17 (talk) 21:36, 18 September 2023 (UTC)Reply[reply]

@Slieb17: As far as I know, prefix wdt means "truthy" statements, that is the values of maximum rank for the property. If there is no value of preferred rank, all normal rank values are included, but if there is at least one value with preferred rank only preferred values are returned. The preferred occupation for Q-Tip (Q42025) is singer (Q177220), therefore this value is used, not rapper (Q2252262), and Q-Tip is not included in your query.
I don't know if singer should be Q-Tip's preferred occupation of if this is an error to be fixed in his item.
A query including all values (or all non deprecated values) is possible but a bit more complex, or at least less usual.--Pere prlpz (talk) 22:24, 18 September 2023 (UTC)Reply[reply]

@Slieb17:: After a bit of research I think I got it:

SELECT DISTINCT ?rapper ?rapperLabel WHERE {

    ?rapper p:P106 ?statement. 
    ?statement ps:P106 wd:Q2252262.

SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}

ORDER BY (?rapperLabel)
Try it!

Now Q-Tip and others are included despite of rank.--Pere prlpz (talk) 22:47, 18 September 2023 (UTC)Reply[reply]

Fantastic - can't thank you enough, for both the explanation AND the working solution. Truly appreciated. Slieb17 (talk) 23:34, 18 September 2023 (UTC)Reply[reply]

Displaying all the participants in a battle Edit

Hello! I have this complex query:

#defaultView:Map{"hide":["?rgb"],"?rgb"}
SELECT 
?veteran 
?veteranLabel 
?veteran_
?layer 
?aita
?aitaLabel 
?aita_
?jaiolekua_aita_
?ama
?amaLabel
?ama_ 
?jaiolekua_ama_
?aitona
?aitonaLabel 
?aitona_ 
?jaiolekua_aitona_ 
?gatazkaLabel
?coord
?rgb 
WITH { SELECT ?veteran ?jaiolekua ?heriotza ?ama ?aita ?aitona WHERE {
?veteran wdt:P241 wd:Q11218.
?veteran wdt:P172 wd:Q126756.
?veteran wdt:P19 ?jaiolekua.
?veteran wdt:P20 ?heriotza.
?veteran wdt:P25 ?ama.
?veteran wdt:P22 ?aita.
OPTIONAL{?aita wdt:P22 ?aitona.}  
} } as %i
with { select ?veteran ?veteran_ ?layer ?ama ?jaiolekua_ama_ ?coord ?rgb WHERE {
INCLUDE %i
?ama wdt:P19 ?jaiolekua_ama.
?jaiolekua_ama wdt:P625 ?coord.
?veteran rdfs:label ?veteranL . FILTER(LANG(?veteranL)="eu")
BIND(CONCAT("Beteranoa: ",?veteranL) as ?veteran_)
?jaiolekua_ama rdfs:label ?jaiolekua_amaL . FILTER(LANG(?jaiolekua_amaL)="eu")
BIND(CONCAT("Amaren jaiolekua: ",?jaiolekua_amaL) as ?jaiolekua_ama_)
BIND("3366CC" as ?rgb)
BIND("Ama" as ?layer)
} } as %j
with { select ?veteran ?veteran_ ?layer ?jaiolekua_aita_ ?aita ?coord ?rgb WHERE {
INCLUDE %i
?aita wdt:P19 ?jaiolekua_aita.
?jaiolekua_aita wdt:P625 ?coord.
?veteran rdfs:label ?veteranL . FILTER(LANG(?veteranL)="eu")
BIND(CONCAT("Beteranoa: ",?veteranL) as ?veteran_)
?jaiolekua_aita rdfs:label ?jaiolekua_aitaL . FILTER(LANG(?jaiolekua_aitaL)="eu")
BIND(CONCAT("Aitaren jaiolekua: ",?jaiolekua_aitaL) as ?jaiolekua_aita_)
BIND("FFCC33" as ?rgb)
BIND("Aita" as ?layer)
} } as %k
with { select ?veteran ?veteran_ ?heriotza ?ama_ ?aita_ ?coord ?layer ?rgb WHERE {
INCLUDE %i
?heriotza wdt:P625 ?coord.
?veteran rdfs:label ?veteranL . FILTER(LANG(?veteranL)="eu")
BIND(CONCAT("Beteranoa: ",?veteranL) as ?veteran_)
?aita rdfs:label ?aitaL . FILTER(LANG(?aitaL)="eu")
BIND(CONCAT("Aita: ",?aitaL) as ?aita_)
?ama rdfs:label ?amaL . FILTER(LANG(?amaL)="eu")
BIND(CONCAT("Ama: ",?amaL) as ?ama_)
BIND("b32425" as ?rgb)
BIND("Heriotza lekua" as ?layer)
} } as %l
with { select ?veteran ?veteran_ ?jaiolekua ?heriotza ?ama_ ?aita_ ?coord ?layer ?rgb WHERE {  
INCLUDE %i
?jaiolekua wdt:P625 ?coord.
?veteran rdfs:label ?veteranL . FILTER(LANG(?veteranL)="eu")
BIND(CONCAT("Beteranoa: ",?veteranL) as ?veteran_)
?aita rdfs:label ?aitaL . FILTER(LANG(?aitaL)="eu")
BIND(CONCAT("Aita: ",?aitaL) as ?aita_)
?ama rdfs:label ?amaL . FILTER(LANG(?amaL)="eu")
BIND(CONCAT("Ama: ",?amaL) as ?ama_)
BIND("00af89" as ?rgb)  
BIND("Jaiolekua" as ?layer)
} } as %m
with { select ?veteran ?gatazka ?coord ?layer ?rgb WHERE {  
INCLUDE %i
?veteran wdt:P607 ?gatazka.
?gatazka wdt:P625 ?coord.
BIND("72777d" as ?rgb)
BIND("Gudua" as ?layer)
} } as %n
with { select ?veteran ?veteran_ ?layer ?jaiolekua_aitona_ ?aitona_ ?coord ?rgb WHERE {
INCLUDE %i

?veteran wdt:P22 ?aita.
?aita wdt:P22 ?aitona. 
  
?aitona wdt:P19 ?jaiolekua_aitona.
?jaiolekua_aitona wdt:P625 ?coord.
?veteran rdfs:label ?veteranL . FILTER(LANG(?veteranL)="eu")
BIND(CONCAT("Beteranoa: ",?veteranL) as ?veteran_)
?jaiolekua_aitona rdfs:label ?jaiolekua_aitonaL . FILTER(LANG(?jaiolekua_aitonaL)="eu")
BIND(CONCAT("Aitonaren jaiolekua: ",?jaiolekua_aitonaL) as ?jaiolekua_aitona_)
BIND("FFCC00" as ?rgb)
BIND("Aitona" as ?layer)
} } as %o
WHERE {
{INCLUDE %j}
UNION
{INCLUDE %k}
UNION
{INCLUDE %l}
UNION
{INCLUDE %m}
UNION
{INCLUDE %n}
UNION
{INCLUDE %o}
SERVICE wikibase:label { bd:serviceParam wikibase:language "eu,en". }
}
Try it!

It works great, but when more than one soldier displayed was in the same battle, it only gives one point with one card, instead of opening all the points and just giving the option to select. Is there a way to show all the soldiers in that battle? Thanks! Theklan (talk) 18:48, 20 September 2023 (UTC)Reply[reply]

Musicians, born between specified years Edit

Query musicians, who were born, e.g., between 1800 and 1900. Osmomysl8 (talk) 21:08, 20 September 2023 (UTC)Reply[reply]

SELECT ?a ?aLabel ?birth_date WHERE {
:        ?a wdt:P31 wd:Q5 . #instance of human
:        ?a wdt:P106/wdt:P279 wd:Q639669 . #occupation a subclass of musician
:        ?a p:P569/psv:P569 ?birth_date_node .
:        ?birth_date_node wikibase:timeValue ?birth_date .
:        SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
:        FILTER(year(?birth_date) > 1800 && year(?birth_date) < 1900).
:    }
:ORDER by ASC(?birth_date)
:
Try it!
This could do. Theklan (talk) 08:29, 21 September 2023 (UTC)Reply[reply]
Yay, this works! Thanks! Osmomysl8 (talk) 15:15, 21 September 2023 (UTC)Reply[reply]

Historical figure with the most ancient known birth date Edit

Hello, I would like to query which is the historical figure with the most ancient birth date. For example, Alexander the Great (Q8409) was born on 20 July 356 BCE, but are there any other instance of human born earlier about whom we know the exact birth date? Nungalpiriggal (talk) 11:29, 22 September 2023 (UTC)Reply[reply]

How to retrieve the city of a building with sparql? Edit

Hello,

For my first SPARQL request, I tried to retrieve some information about the event "journées européennes des amateurs de nœuds" (Q112064134). This item groups each session in other items (since 2001 to 2023).

The result is correct, but I would like to improve it a city column.

SELECT DISTINCT ?session ?label_fr ?location ?city ?start ?end
WHERE {
  ?item wdt:P393 ?session .
  ?item wdt:P31 wd:Q112064134 .
  ?item rdfs:label ?label_fr filter(lang(?label_fr) = "fr") .
  ?item wdt:P276 ?site .
  OPTIONAL { ?site rdfs:label ?location filter(lang(?location) = "fr") }
  ?item wdt:P580 ?start .
  ?item wdt:P582 ?end .
}
ORDER BY ?label_fr
Try it!

But the location of the event is sometimes the city itself or a specific location in the city. Anyone knows how to retrieve this information?

Jpgibert (talk) 12:24, 22 September 2023 (UTC)Reply[reply]

@Jpgibert: Probably something along these lines ... look up the P276 or P131 property paths until you find something that is a human settlement:
SELECT DISTINCT ?session ?itemLabel ?cityLabel ?site ?siteLabel ?start ?end
WHERE {
  ?item wdt:P393 ?session .
  ?item wdt:P31 wd:Q112064134 .
  ?item wdt:P276 ?site .
  OPTIONAL {?site wdt:P276*/wdt:P131* ?city. hint:Prior hint:gearing "forward". 
            ?city wdt:P31/wdt:P279* wd:Q486972. hint:Prior hint:gearing "forward".}
  ?item wdt:P580 ?start .
  ?item wdt:P582 ?end .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }

}
ORDER BY ?itemLabel
Try it!
--Tagishsimon (talk) 13:44, 23 September 2023 (UTC)Reply[reply]
@Tagishsimon: Many thanks for your help. Jpgibert (talk) 15:45, 23 September 2023 (UTC)Reply[reply]

Bilingual labels Edit

I'm trying to build a list of physical places in New Zealand and both their en and mi language labels, as the first step to improve mi language labels. I've tried without success queries such as:

SELECT DISTINCT ?item ?itemLabel ?labelen ?labelmi WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,mi". }
  {
    SELECT DISTINCT ?item WHERE {
      ?item p:P31 ?statement0.
      ?statement0 (ps:P31/(wdt:P279*)) wd:Q2221906.
      ?item p:P17 ?statement1.
      ?statement1 (ps:P17/(wdt:P279*)) wd:Q664.
      ?item rdfs:label ?labelen.
      ?itme rdfs:label ?labelmi.
      FILTER(LANG(?labelen) = "en").
      FILTER(LANG(?labelmi) = "mi").
    }
    LIMIT 100
  }
}
Try it!

121.99.219.62 05:44, 23 September 2023 (UTC) Reply[reply]

SELECT DISTINCT ?item ?labelen ?labelmi WHERE {
    ?item wdt:P17 wd:Q664; wdt:P31/wdt:P279* wd:Q58416391.
    optional{?item rdfs:label ?labelen. FILTER(LANG(?labelen) = "en")}
   # optional{?item rdfs:label ?labelmi. FILTER(LANG(?labelmi) = "mi")}
   filter not exists{?item rdfs:label ?labelmi. FILTER(LANG(?labelmi) = "mi")}
 } limit 100
Try it!

This simple query gives you a list of spatial entities in NZ with English but without Maori labels. if you replace the "filter not exists" line with the former "optional" labelmi, you get a list with existing English and Maori labels DL2204 (talk) 09:38, 23 September 2023 (UTC)Reply[reply]