TrustGraphGet Started

SPARQL

SPARQL Protocol and RDF Query Language - the standard query language for RDF/Semantic Web data, analogous to SQL for relational databases.

Infrastructure

SPARQL is the standard query language for RDF triple stores and Semantic Web data.

Basic Query

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX ex: <http://example.com/>

SELECT ?person ?name ?email
WHERE {
  ?person a foaf:Person .
  ?person foaf:name ?name .
  ?person foaf:mbox ?email .
  ?person ex:worksAt ex:TechCorp .
}
ORDER BY ?name
LIMIT 10

Pattern Matching

# Find people and their managers
SELECT ?employee ?manager
WHERE {
  ?employee ex:reportsTo ?manager .
  ?employee a ex:Employee .
  ?manager a ex:Manager .
}

# Optional patterns
SELECT ?person ?email
WHERE {
  ?person a foaf:Person .
  ?person foaf:name ?name .
  OPTIONAL { ?person foaf:mbox ?email }
}

See Also

Examples

  • SELECT ?person ?company WHERE { ?person worksAt ?company }
  • Querying DBpedia to find all scientists born in a specific city

Related Terms

Learn More