Shortcuts: WD:RAQ, w.wiki/LX

Wikidata:Request a query

From Wikidata
Jump to navigation Jump to search

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 2024/06.

Missing descriptions not really missing

[edit]

Hi, trying this FILTER still gets the descriptions, but they are not in fact missing.

SELECT ?item ?itemLabel ?itemDescription ?itemdesc_fr WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
  ?item wdt:P31 wd:Q55488; wdt:P17 wd:Q212.
FILTER(NOT EXISTS {    
  ?item schema:description ?itemdesc_fr.
    FILTER(LANG(?itemdesc) = "fr")
  }) 
}
Try it!

Bouzinac💬✒️💛 05:39, 23 May 2024 (UTC)[reply]

Change the variable name in the filter to ?itemdesc_fr Piecesofuk (talk) 08:12, 23 May 2024 (UTC)[reply]
Thanks Bouzinac💬✒️💛 16:53, 23 May 2024 (UTC)[reply]

Shouldn't McDonald's have P17 for all countries it's in?

[edit]

Hi, first time posting. I'm wondering, McDonald's Q38076 (and many other retail chains) are present all over the world. However, the only hint about this is the fact that they have a website in a certain language. So my question: shouldn't McDonald's have a country property Property:P17 for each country it's in? Thanks! Gradiente4 (talk) 12:21, 25 May 2024 (UTC)[reply]

Data modelling questions are more suited for Project chat. People who are good at querying aren't necessarily good at data modelling and vice versa. I would suggest to look at the items for Coca Cola co. and Wikimedia Foundation which are two other multinationals. It would seem they only list the country of the parent organization. Infrastruktur (talk) 16:15, 25 May 2024 (UTC)[reply]
A way of querying https://w.wiki/ABtm
It appears there are clear lack of data. I don't know if it is desirable to input every McDonald's restaurant inside wikidata, all the more as it is complicated between franchises(=independent but can use the name Mcdo) and subsidiaries (owner is McDo). Bouzinac💬✒️💛 08:06, 26 May 2024 (UTC)[reply]

Normalised truthy values

[edit]

Getting truthy values is easy with wdt:. Getting normalises values is possible with p: and psn: is also possible (as I learned in Wikidata:Request_a_query/Archive/2023/10#Height_in_a_single_unit). However, when using p: and psn: I get all values, with all ranks. How can I get only the truthy values?

For example, in this query Bac de Roda Bridge (Q3396457) has two values for length (P2043) and longest span (P2787) (one of them preferred). Using wdt I would get only that value (which is good) but if I want to make sure that I get values in meters, I get the two values for those dimensions.

# Ponts amb mides
SELECT DISTINCT ?item ?itemLabel ?llarg ?ample ?llum ?alt
 WHERE {
 VALUES ?tipus {wd:Q12280}
 ?item wdt:P17 wd:Q29.
 ?item wdt:P31/wdt:P279* ?tipus.
   ?item wdt:P166 [].
        OPTIONAL {?item p:P2043  ?sllarg.
               ?sllarg psn:P2043  ?sllargn.
                ?sllargn wikibase:quantityAmount ?llarg. 
              }
        OPTIONAL { ?item wdt:P2787 [].
          ?item p:P2787  ?sllum.
               ?sllum psn:P2787  ?sllumn.
                ?sllumn wikibase:quantityAmount ?llum. 
              }
        OPTIONAL {?item p:P2049  ?sample.
               ?sample psn:P2049  ?samplen.
                ?samplen wikibase:quantityAmount ?ample. 
              }
        OPTIONAL {?item p:P2048  ?salt.
               ?salt psn:P2048  ?saltn.
                ?saltn wikibase:quantityAmount ?alt. 
              }
   SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],ca,en,es,fr".}   
}
Try it!

I tried to use wdtn: but it didn't work (it seems that it is still to be implemented for values with units).

How can I get normalised truthy values? Pere prlpz (talk) 23:14, 25 May 2024 (UTC)[reply]

I believe the documentation uses the term 'truthy' incorrectly. What you get when you use "wdt:" i consistently call best-values to avoid confusion. This returns preferred rank values if they exist, if not, they return normal ranked values. Truthy values is really the set of preferred and normal ranked values. In your first optional add the line "?sllarg a wikibase:BestRank ." and do similarly on the other optionals. Infrastruktur (talk) 21:52, 26 May 2024 (UTC)[reply]
@Infrastruktur: Thank you. It works fine.--Pere prlpz (talk) 22:06, 26 May 2024 (UTC)[reply]

List of all U.S. Presidents and their Vice Presidents

[edit]

Hi, I'm trying to fetch all U.S. Presidents and their associated Vice-President(s). I see President of the United States (President of the United States (Q11696)) has the officeholder (officeholder (P1308)) and deputy (substitute/deputy/replacement of office/officeholder (P2098)) properties, latter of which points to Vice-President, which then also has the officeholder property, but I'm unsure on how to structure the query. UAgnxfdZUzfW8vY (talk) 04:56, 26 May 2024 (UTC)[reply]

I'm afraid that could be hard to do in a query because after examining Millard Fillmore (Q12306) the only thing I can see linking presidents and their vice-presidents are the dates of start and end.--Pere prlpz (talk) 10:39, 26 May 2024 (UTC)[reply]

mountains over 7000 m on a map?

[edit]

Thank you 115.188.127.196 07:59, 26 May 2024 (UTC)[reply]

Here is it:
# Mountains over 7000 m
SELECT DISTINCT ?item ?itemLabel ?alt ?coord
 WHERE {
   ?item wdt:P31 wd:Q8502.
   ?item p:P2044  ?salt.
               ?salt psn:P2044  ?saltn.
                ?saltn wikibase:quantityAmount ?alt. 
   ?item wdt:P625 ?coord.
   FILTER(?alt > 7000)
   SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],ca,en,es,fr".}   
}
ORDER BY DESC(?alt)
#defaultView:Map
Try it!
If you view the result in table mode, you will see there are several heights for some peaks (notably Mount Everest (Q513)), because to get normalized values (heights in meters, even if they are entered using another unit) we get all statements, including those not of maximum rank. If someone answers my last question in this page we will be able to solve this, too.--Pere prlpz (talk) 11:05, 26 May 2024 (UTC)[reply]

Find same codes sharing

[edit]

Hi, inside this query https://w.wiki/ACEF, how to filter out the unique identifiers (that is, get only those that share same identifiers) ? Bouzinac💬✒️💛 20:27, 26 May 2024 (UTC)[reply]

My try:
SELECT ?item ?itemLabel ?idnt ?numItems
WITH {
SELECT ?idnt (COUNT(DISTINCT(?item)) AS ?numItems) WHERE {
  ?item   wdt:P5696 ?idnt.
} 
GROUP BY ?idnt
} AS %1
WHERE {
  INCLUDE %1.
  ?item   wdt:P5696 ?idnt.
  FILTER(?numItems > 1)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!
Does it work for you? Pere prlpz (talk) 22:18, 26 May 2024 (UTC)[reply]
Exactly what I needed. Thanks a lot ! Bouzinac💬✒️💛 07:18, 27 May 2024 (UTC)[reply]

English footballers data

[edit]

I am looking to create lists on wikidata of english football club players, their date of birth, year of debut, age at death and number of appearances. So far I have only been able to generate date of birth for players of each club. Is it possible to have all these parameters in one search / in one table? 123.208.182.177 09:55, 29 May 2024 (UTC)[reply]

Commons files with an inception date of 2015-08-15

[edit]

On the Commons query service, is it possible to query all files with a certain inception date (wdt:P571)? I'm not sure how to use dateTime, timeValue, timePrecision, etc. or even if those are necessary for this. Nosferattus (talk) 04:49, 30 May 2024 (UTC)[reply]

You mean like this: Try it!
? --Strahtw (talk) 07:50, 5 June 2024 (UTC)[reply]

What is the "main type" of each entity

[edit]

Hi. I'm updating OSM with the tag "name:etymology:wikidata", and I know howto export from OSM all those tags in a city (city's streets). But I can't imagine how to request Wikidata to retrieve for each Wikidata ID the "main type" and another main information, like it's a "human / gender", a "locality / human settlement / Country", a "war battle / country" ans so on. I know programming, so I can do a loop with each entity ID ;-)

For exemple "Q3261145" is a human of the male gender, "Q1686757" is a city of Belguim, "Q38789" is a battle in russia, "Q6565319" is a species of plant ...

Thanks a lot for your help <3 Cyrille37 (talk) 10:26, 2 June 2024 (UTC)[reply]

How to return a qualifier for a specific property

[edit]

Hello there. I am researching the National Register of Historic Places.

I've created a simple query that returns any item which has 'heritage designation' (P1435) of 'National Register of Historic Places listed place' (Q19558910). It results in about 73,425 items: https://w.wiki/AJMR

If you click on any of the Wikidata items for these NRHP listings, you'll see most (if not all) have a 'start time' qualifier listed under their 'National Register of Historic Places listed place' property. This is the date the building (or historic district) was added to the National Register sometime after its inception in 1966. 'start time' is also used for other heritage designation properties (National Historic Landmark, UNESCO, etc) for some of these 73,425 items.

What I want to do next is to include a column in the results that specifies the 'start time' qualifier for specifically the 'National Register of Historic Places listed place' (Q19558910) property.

I am trying the following query, which somehow only results in 48 items for me: https://w.wiki/AJMe

I know I could be doing something differently because: -there should be many more results of 'National Register of Historic Places listed place' items than 48 -some of the listed 'start times' are not the specific 'start times' I'm looking for. I only want start time for 'National Register of Historic Places listed place', not any other start time that might be used.

Any advice on tailoring this query would be much appreciated. I've searched a lot of tutorials for the past couple hours and can't find a solution.

Once I get a list of each 73,425 result, with its correct National Register heritage designation start time, I just want to create a simple tally of quantity per year. I can export the results and do this count in a spreadsheet, but if there is an easy way to formulate the correct query to do the count per year as well, that would be fantastic.

Thank you to anyone who can help! Openpreservation.xyz (talk) 00:49, 6 June 2024 (UTC)[reply]

The problem is that the start time (P580) is only created as a property for the 48 items you receive. For most of the others, the start time is stored as a qualifier of the heritage designation (P1435).
Here is a query that lists these: https://w.wiki/AJS7
However, the other 48 are missing, so perhaps this should be standardized.
Now, however, some entries are displayed several times if they have several heritage categories. As I am only moderately familiar with this myself, I can't help you any further. But if you have a solution for this, such as only the start times of the entry in the National Register of Historic Places listed place (Q19558910) let me know, because I also had the problem once and I have no solution for it so far. Strahtw (talk) 05:58, 6 June 2024 (UTC)[reply]
Thank you @Strahtw for giving it a shot.
Hopefully someone else can help us fine tune the query to get just National Register items with just National Register start dates. Openpreservation.xyz (talk) 16:01, 6 June 2024 (UTC)[reply]
I was looking at the documentation and found an example with filters which I thought it could help. I tried it and got the query you want:
SELECT ?item ?itemLabel ?start_time WHERE {
  ?item wdt:P1435 wd:Q19558910;
  p:P1435 ?Cat.
  optional { ?Cat pq:P580 ?start_time. } 
  FILTER EXISTS { ?Cat ps:P1435 wd:Q19558910 }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
}
Try it!
But now I get 74209 entries. But some results have two entries with National Register of Historic Places listed place (Q19558910). For example Broadway Bridge (Q4972421). This doubles have to be corrected maybe.
--Strahtw (talk) 07:38, 7 June 2024 (UTC)[reply]

A list of all museums in the German State of North-Rhine Westphalia

[edit]

This querry: SELECT DISTINCT ?item ?itemLabel WHERE {

 SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
 {
   SELECT DISTINCT ?item WHERE {
     ?item p:P31 ?statement0.
     ?statement0 (ps:P31) wd:Q33506.
     ?item p:P131 ?statement1.
     ?statement1 (ps:P131/(wdt:P131*)) wd:Q1198.
   }
   LIMIT 1000
 }

}

obviously doesn't list all the {{q| Q33506}} museums in {{q| Q1198}} North-Rhine Westphalia. 

For instance the {{q| Q1798475}} LWL-Museum für Kunst und Kultur is not listed. Why? Is something missing in the entry of the museum? Is it because the museum is listed as a {{q| Q207694}} Kunstmuseum?

In other word is it necessary to include some kind of deep-search into the querry?

When all this is done, I have a second wish: How do I visualize the results in a clickable map of North-Rhine Westphalia?

Thanks

--Wuselig (talk) 11:54, 6 June 2024 (UTC)[reply]

Flag more accurate coordinates // less accurate

[edit]

Hi, in this list, there are multiples coordinates at same rank. Is there a way to distinguish low precision P625 // good precision P625 [the more decimals ==> the more precise coordinates]. Bonus : is there a tool to set en masse the more precise P625 as preferred rank ? Bouzinac💬✒️💛 13:00, 8 June 2024 (UTC)[reply]