Basic

Property Paths

Navigate relationships with flexible patterns. Property paths let you follow chains of properties, match alternatives, and traverse hierarchies in a single expression.

Understanding Property Paths

Property paths extend basic triple patterns with operators for sequences (/), alternatives (|), repetition (* + ?), and inversion (^). They're powerful for traversing hierarchies, following chains, and matching flexible patterns.

Alternative Paths (|)

Instance or Subclass
Run ↗
SELECT ?item ?itemLabel ?typeLabel
WHERE {
  ?item (wdt:P31|wdt:P279) wd:Q7889 .
  ?item (wdt:P31|wdt:P279) ?type .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 20

The pipe operator (|) matches either property. This common pattern finds items that are instances of or subclasses of video games, treating both direct instances and subclasses alike.

Sequence Paths (/)

Follow Chain of Properties
Run ↗
SELECT ?person ?personLabel ?countryLabel
WHERE {
  ?person wdt:P31 wd:Q5 ;
          wdt:P19/wdt:P17 ?country .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 20

The slash (/) chains properties together. Instead of separate patterns for birth place and its country, this follows place of birth (P19) then country (P17) in a single expression.

Repetition Paths (* + ?)

Traverse Class Hierarchy
Run ↗
SELECT DISTINCT ?class ?classLabel
WHERE {
  wd:Q146 wdt:P31/wdt:P279* ?class .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

The asterisk (*) means "zero or more times". This finds the type of house cat, then follows the subclass-of chain (P279) upward to find all ancestor classes: cat → felid → carnivore → mammal → animal → organism.

Parent Chain (One or More)
Run ↗
SELECT DISTINCT ?ancestor ?ancestorLabel
WHERE {
  wd:Q9682 wdt:P40+ ?ancestor .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

The plus (+) means "one or more times". This follows the child (P40) relationship recursively to find all descendants. Use + when you need at least one step; use * when zero steps (the starting point) is acceptable.

Inverse Paths (^)

Follow Relationship Backwards
Run ↗
SELECT ?parent ?parentLabel
WHERE {
  wd:Q9682 ^wdt:P40 ?parent .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

The caret (^) inverts a property direction. While P40 means "has child", ^P40 means "is child of", effectively finding parents. This is useful when the property points the opposite direction from what you need.

Key Entities Used in Examples

Entity ID Description
video game wd:Q7889 Electronic game with video output
human wd:Q5 Any human being
house cat wd:Q146 Domesticated cat
Elizabeth II wd:Q9682 Queen of the United Kingdom
instance of wdt:P31 Type or class of item
subclass of wdt:P279 Parent class in hierarchy
place of birth wdt:P19 Location where born
country wdt:P17 Sovereign state of location
child wdt:P40 Person's child