SPARQL Query and Command Clauses

SPARQL statements are typically constructed using the following basic query commands, optional clauses, or other query solution modifiers:

Standard Query or Result Commands

  • SELECT: Run SELECT queries when you want to find and return all of the data that matches certain patterns.
  • CONSTRUCT: Run CONSTRUCT queries when you want to create or transform data based on the existing data.
  • ASK: Run ASK queries when you want to know whether a certain pattern exists in the data. ASK queries return only "true" or "false" to indicate whether a solution exists.
  • DESCRIBE: Run DESCRIBE queries when you want to view the RDF graph that describes a particular resource.

Optional Query Clauses

All query statements may also include one or more of the following clauses:

  • PREFIX Clause: The optional PREFIX clause declares the abbreviations that you want to use to reference URIs in the query.
  • FROM Clause: The optional FROM clause defines the data sets or graphs to query. By default, if you do not specify the FROM clause, the scope of a query is limited to the default graph.
  • WHERE Clause: The WHERE clause specifies the query pattern for data to match in the graphs or data sets specified in the query.

Additional Query Solution Modifiers

The following optional query modifiers enable you to restrict, group, sort, or further refine query results:

  • ORDER BY: This modifier sorts the result set in a particular order. It sorts query solution results based on the value of one or more variables.
  • OFFSET: Using this modifier in conjunction with LIMIT and ORDER BY returns a slice of a sorted solution set, for example, for paging.
  • LIMIT: This modifier puts an upper bound on the number of results returned by a query.
  • GROUP BY: This modifier is used with aggregate functions and specifies the key variables to use to partition the solutions into groups. For information about AnzoGraph GROUP BY clause extensions, see Advanced Grouping Sets.
  • HAVING: This modifier is used with aggregate functions and further filters the results after applying the aggregates.
Related Topics