SPARQL Basics

With graphs storing data as triples, most forms of SPARQL queries and related graph operations specify a SELECT clause, which identifies the variables and data values to appear in the query results, and a WHERE clause provides the basic graph pattern to match against the data stored in an AnzoGraph graph (the default graph or a specific named graph). Additional statement clauses, such as ORDER BY, GROUP BY, and LIMIT provide additional ways to shape results returned from a query or other SPARQL statements. SPARQL statements may also include built-in SPARQL functions or other functions provided by AnzoGraph. (Refer to the SPARQL Language Reference for a listing and description of supported built-in SPARQL and other AnzoGraph functions.)

For instructions on retrieving a list of all supported SPARQL functions for your AnzoGraph release, see How do I get a list of all AnzoGraph functions?

Triple patterns specified in a SPARQL query are like the triples stored in RDF format except that each of the subject, predicate and object may be a variable. For example:

SELECT ?predicate ?object
FROM <tickit>
WHERE {
  <event100> ?predicate ?object
}
ORDER BY ?predicate

Based on the triples in the sample <tickit> graph, this query would return the following result:

predicate                                       | object
------------------------------------------------+----------------------
catid                                           | category8
dateid                                          | date2129
eventname                                       | Siegfried
http://www.w3.org/1999/02/22-rdf-syntax-ns#type | event
starttime                                       | 2008-10-30T15:00:00Z
venueid                                         | venue300
6 rows

In this example, the query returns a list of all predicate values from an event ticketing graph database, <tickit>, for a specific event ID, <event100>.

The <Tickit> graph provides a simple example data set that captures sales activity for a fictional Ticketing website where people buy and sell tickets for sporting events, shows, and concerts.

See Sample Data, Tutorials, and Benchmarks for instructions on how to load the Tickit graph into AnzoGraph. The sample data and accompanying tutorials also help familiarize you with using SPARQL and Cypher query languages in AnzoGraph. Also see the SPARQL Language Reference for syntax, usage, and examples of SPARQL commands and functions.

Here are some additional details about query commands, functions, and other clauses comprising SPARQL statements:

Related Topics