Shortcuts: WD:RAQ, w.wiki/LX

Wikidata:Request a query

From Wikidata
(Redirected from Wikidata:RAQ)
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/05.

Climate change related items[edit]

Hi everyone. I have a set of nearly 200 Wikidata items and I want to know if there's a chance to make a query to know:

  • in how many Wikipedias the article exists?
  • and if they are available on es.wiki, pt.wiki, en.wiki and fr.wiki separately?

Is all this possible? I look forward to your comments. Thank you very much. Paula (WDU) (talk) 16:44, 6 May 2024 (UTC)[reply]

You may try this:
SELECT ?item (COUNT(?wiki) AS ?wikis) ?en ?es ?fr ?pt
WHERE {
  hint:Query hint:optimizer "None".
  VALUES ?item { wd:Q20 wd:Q21 wd:Q22 } # <- Replace with your set of items
  OPTIONAL { ?wiki schema:about ?item; schema:isPartOf / wikibase:wikiGroup "wikipedia". }
  OPTIONAL { ?en_ schema:about ?item; schema:isPartOf <https://en.wikipedia.org/>; schema:name ?en. }
  OPTIONAL { ?es_ schema:about ?item; schema:isPartOf <https://es.wikipedia.org/>; schema:name ?es. }
  OPTIONAL { ?fr_ schema:about ?item; schema:isPartOf <https://fr.wikipedia.org/>; schema:name ?fr. }
  OPTIONAL { ?pt_ schema:about ?item; schema:isPartOf <https://pt.wikipedia.org/>; schema:name ?pt. }
}
GROUP BY ?item ?en ?es ?fr ?pt
ORDER BY DESC(?wikis)
Try it!
--Flipping Switches (talk) 04:26, 8 May 2024 (UTC)[reply]
@Flipping Switches, thank you very much! It works. Best, Paula (WDU) (talk) 19:45, 13 May 2024 (UTC)[reply]

Finding connections between celebrities[edit]

I am looking to build a query where I can show a list of well-known people (i.e. celebrities, athletes, etc) who are connected to a specific person, and then rank them by fame level (as approximated by the number of wikibase:sitelinks for a person -- although open to any alternate fame approximations).

For example, if I want to list any person who has been on a project or had a professional/personal relationship with Seth Rogen (they worked together, they are friends, they are on the same board, etc), how would I do that? For the output columns, I'd like: 1) Name of celebrity 2) Link to wiki page 3) QID 4) Hometown state or country (if not in US)

Thanks in advance! QueryBeginner (talk) 19:40, 14 May 2024 (UTC)[reply]

@QueryBeginner: The main problem where translating your question into a query is to define what "connected to a specific person" mean in terms of Wikidata claims. Here is the query with the people that have worked with Seth Rogen (Q220308) as cast member (P161) or voice actor (P725).
SELECT DISTINCT ?coworker ?coworkerLabel ?sitelinks
  WITH {
    SELECT ?work WHERE {
  {?work wdt:P161 wd:Q220308.}
  UNION
  {?work wdt:P725 wd:Q220308.}
    } } AS %1
   WHERE {
     INCLUDE %1
     {?work wdt:P161 ?coworker.}
     UNION
     {?work wdt:P725 ?coworker.}
     ?coworker wikibase:sitelinks ?sitelinks.
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],ca,en" } .
}
ORDER BY desc(?sitelinks)
Try it!
Clickbait: the first ones will surprise you. Just in case you want to check in which film they worked with Seth Rogen (Q220308), there is another query showing it:
SELECT DISTINCT ?coworker ?coworkerLabel ?work ?workLabel
  WITH {
    SELECT ?work WHERE {
  {?work wdt:P161 wd:Q220308.}
  UNION
  {?work wdt:P725 wd:Q220308.}
    } } AS %1
   WHERE {
     INCLUDE %1
     {?work wdt:P161 ?coworker.}
     UNION
     {?work wdt:P725 ?coworker.}
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],ca,en" } .
}
Try it!

--Pere prlpz (talk) 17:09, 20 May 2024 (UTC)[reply]

Is there a query available to list all the names from this page?[edit]

I am hoping to list all the names on this page as a query output, and rank them by fame, as defined as the number of wikibase:sitelinks: QueryBeginner (talk) 19:53, 14 May 2024 (UTC)[reply]

I don't think there is a way to make a query including articles linked from a Wikidpedia page. However, using PetsCan you could probably get items linked from a Wikipedia page which have more than a given minimum number of sitelinks. Would that fit your purpose? Pere prlpz (talk) 08:21, 21 May 2024 (UTC)[reply]

Help simplifying query: Request all officeholders (p:P1308) and applies to jurisdiction (p:P1001) of governors of a mexican state (wdt:Q17810142)[edit]

Hello community, I have a working query that retrieves the values of 2 properties of a query. It works I just think there's a better way to write this. I'm looking for something along the lines of:

From all items that are subclass wdt:P279 of state governor of mexico wd:Q17810142, give me the values for p:P1001 and p:P1308

SELECT ?item ?itemLabel ?state ?stateLabel
WHERE {
  # from all items that are subclass of state governor of mexico retrieve all items that have property p:P1308 and all items that have property p:1001
  ?wiki_items p:P1308 ?statement. 
  ?wiki_items wdt:P279 wd:Q17810142.
  ?statement ps:P1308 ?item.
  ?wiki_items p:P1001 ?other_statement.
  ?other_statement ps:P1001 ?state.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!

Basicavisual (talk) 20:18, 14 May 2024 (UTC)[reply]

Football_clubs with stadiums and coordinates[edit]

I am trying to collect football clubs with country/stadium/coordinates. I tried "association football club" - "home venue","country" and "coordinate location" which was translated to this query:

SELECT ?association_football_club ?association_football_clubLabel ?country ?countryLabel ?home_venue ?home_venueLabel ?coordinate_location WHERE {

 SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
 ?association_football_club wdt:P31 wd:Q476028.
 OPTIONAL { ?association_football_club wdt:P17 ?country. }
 OPTIONAL { ?association_football_club wdt:P115 ?home_venue. }
 OPTIONAL { ?association_football_club wdt:P625 ?coordinate_location. }

}

it gives me 39000 football clubs in countries which is great!!!

The goal is to have the name of the stadium with the stadium coordinates. If there is no stadium, the coordinates of the football club might be good so there are at least some coordinates.

But there are lots of problems with missing stadiums and coordinates. Can I change the query to get a complete result list? Marlons Friends (talk) 10:24, 15 May 2024 (UTC)[reply]

That indicates there is data missing in our database which needs to be added, nothing to do with your query. Sjoerd de Bruin (talk) 13:27, 15 May 2024 (UTC)[reply]

Item is part of itself[edit]

I am baffled why this simple entry for a weapon EOC BL 10 inch/45 gun (Q5323780) is regarded as part of itself.

SELECT DISTINCT ?item ?itemLabel  WHERE {
SERVICE wikibase:label {bd:serviceParam wikibase:language "en-GB,en,fr,de,es,pt,pl,nl,cs".}
{
SELECT DISTINCT ?item  WHERE {
    ?item wdt:P361* wd:Q5323780
    }
  }
}
Try it!

Vicarage (talk) 11:17, 16 May 2024 (UTC)[reply]

"*" means 0 or 1 applications of the property. Zero application means no application so the class fits itself. --Infovarius (talk) 14:46, 17 May 2024 (UTC)[reply]
OH, I always thought it was a nesting level, as in wdt:P31/wdt:P279* wd:something, I'll use P361+ then. Thanks. Vicarage (talk) 15:51, 17 May 2024 (UTC)[reply]

instance of (P31) of chiral muscle organ type (Q125984341) that doesn't have exactly two instances with no subclasses[edit]

I want a query that shows all instance of (P31) of chiral muscle organ type (Q125984341) that doesn't have exactly two instances and neither of the two instances has any subclasses (as those are likely misclassified). ChristianKl15:39, 19 May 2024 (UTC)[reply]

People with a gender that isn't male[edit]

For the purposes of motivating people to help combat the gender gap, I'd like to be able to filter results of some existing queries (at Wikidata:ExLibris-Primo) with clauses to remove the men. Property:P21 has so many possible values that listing them can't be the best solution to this problem? "Fish & Chip" flavoured ice cream (talk) 05:06, 20 May 2024 (UTC)[reply]

A FILTER should work for this, see for example this list of stunt performers on wikidata who are not male:
SELECT DISTINCT ?item ?itemLabel ?genderLabel
WHERE {
    ?item wdt:P31 wd:Q5. # humans
    ?item wdt:P106 wd:Q465501. # who are stunt performers
  
    ?item wdt:P21 ?gender. # get their gender (because this is not wrapped in OPTIONAL{}, items with a null gender are excluded from the results)
    FILTER (?gender != wd:Q6581097) # not male
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
ORDER BY DESC(?genderLabel)
Try it!
PaperHuman (talk) 11:01, 20 May 2024 (UTC)[reply]

Values formatted with unit[edit]

I know (from Wikidata:Request_a_query/Archive/2023/10#Height_in_a_single_unit) that I can get the value and unit of a claim with units, both using the original unit and the normalised one.

However, now I would like to get the value formatted with its unit. For example, "27 meter", "27 meters" or "27 m". I suppose that I could get the value and the unit and paste them together using CONCAT, but the question is whether there is a simpler way or a ready made example to copy from. Pere prlpz (talk) 16:19, 20 May 2024 (UTC)[reply]

Stuffs not functionning but fuctions[edit]

Among things having not state of use (P5817) = in use (Q55654238) (supposedly not functionning), what are those having date of official opening (P1619) > date of official closure (P3999) ? Bouzinac💬✒️💛 21:17, 21 May 2024 (UTC)[reply]

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]