What is SPARQL?

SPARQL is a set of standards for graph databases published by the W3C, but the name is most often used to refer to the query language.  

As a query language, SPARQL can be used to add, remove and retrieve data from RDF-style graph databases. SPARQL queries can not only match patterns of subject-predicate-object triples, but can also use mathematical operations and a wide range of utility functions to create filters and new variable bindings. They can test for the absence of a pattern (negation), contain optional sections and even entire sub-queries. The results can be freely ordered, grouped and those groups can be aggregated over.

SPARQL Example:

A basic SELECT query can look like this:

SELECT ?name WHERE {
?person a :Person .
?person :hasName ?name
}

This query returns the names of all people in the database. But we could make it more complex:

SELECT ?name ?dob WHERE {
?person a :Person .
?person :hasName ?name .
?person :hasDateOfBirth ?dob .
FILTER(?dob < “2000-01-01”^^xsd:date)
} ORDER BY ?name

This would give us an alphabetical list of all the people in the database who were born before the year 2000.

Down arrow icon.