NanoSocrates/docs/SPARQL.md
Christian Risi 2487d44abd Added SparQL
2025-09-17 12:48:33 +02:00

807 B

SparQL

Note

Resources taken from this website

SQL Queries

SELECT

SELECT ?var1, ?var2, ...

WHERE

WHERE {
    pattern1 .
    pattern2 .
    ...
}

FILTER

It's used to restrict WHERE clauses

WHERE {
  ?person <http://example.com/hasCar> ?car .
  FILTER (?car = <http://example.com/Car1>)
}

OPTIONAL

It's used to fetch available content if exists

SELECT ?person ?car
WHERE {
  ?person <http://example.com/hasCar> ?car .
  OPTIONAL {
    ?car <http://example.com/hasColor> ?color .
  }
}

LIMIT

Limits results

LIMIT 10 -- Take only 10 results

SparQL functions

COUNT

SELECT (COUNT(?person) AS ?count)
WHERE {
  ?person <http://example.com/hasCar> ?car .
}