sparqlsemantic-webdbpediawikidata

SPARQL "any" relationship filter


I want to retrieve entities with any relation to some other entity. Consider following query:

SELECT ?item ?itemLabel 
WHERE 
{
  ?item wdt:P31 wd:Q28598684. 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 
# Helps get the label in your language, if not, then en language
}

Here, I would like to have 'wdt:P31' to be any relationship and I want to return this relationship as well. Is that possible?


Solution

  • As said in comments by the author of the question: you can simply use a variable in the place of the relationship to get the relationship.

    select ?item ?property ?itemLabel ?propertyLabel {
      ?item ?property wd:Q28598684. 
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 
    }