SPARQL examples – count all statements

Here’s a SPARQL query that counts all statements (triples) in a repository.

SELECT (COUNT(?s) AS ?triples) WHERE { ?s ?p ?o }

Note that this can be a long running query. For me it took took 21 seconds to count the statements in a repository with 30 million triples.