1

I am trying to create a SPARQL query that will retrive only the external identifiers for a record. Basically, I want to retrieve the items listed under the "Identifers" section on one of the dedicated pages, e.g. https://www.wikidata.org/wiki/Q112133367 includes the IMDB movie ID and the Rotten Tomatoes ID for the film.

I am able to get all the available properties for an item (I know the item's Wikidata ID). This is something like SELECT * FROM wikidata WHERE id='Q112133367':

SELECT ?value ?valueLabel ?prop ?propLabel {
    wd:Q112133367 ?prop ?value .
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

I've tried using the VALUES syntax, which I think is equivalent in this case (?):

SELECT ?item ?value ?valueLabel ?prop ?propLabel ?p2 ?p2Label {
  VALUES (?item) {(wd:Q112133367)}
  ?item ?prop ?value .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

But so far I have been unable to limit the properties returned to only ones that are External Identifiers. This is what I tried, but this results in "No matching records found":

SELECT ?item ?value ?valueLabel ?prop ?propLabel ?p2 ?p2Label {
  VALUES (?item) {(wd:Q112133367)}
  ?item ?prop ?value .
  ?prop wikibase:propertyType wikibase:ExternalId .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
Everett
  • 8,746
  • 5
  • 35
  • 49
  • 1
    `SELECT ?item ?value ?valueLabel ?prop ?propLabel ?p2 ?p2Label { VALUES (?item) {(wd:Q112133367)} ?item ?a ?value . ?prop wikibase:propertyType wikibase:ExternalId . ?prop wikibase:directClaim ?a . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } }` – UninformedUser Jun 18 '22 at 02:35
  • 1
    Thanks, that seems to do the trick! If you want to post this as an answer, then it can be marked as a solution. – Everett Jun 18 '22 at 12:22

0 Answers0