# SparQL

> [!NOTE]
> Resources taken from [this website](https://sparql.dev/)

## SQL Queries

### SELECT

```SQL
SELECT ?var1, ?var2, ...
```

### WHERE

```SQL
WHERE {
    pattern1 .
    pattern2 .
    ...
}
```

### FILTER

It's used to restrict [`WHERE`](#where) clauses

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

### OPTIONAL

It's used to fetch available content if exists

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

### LIMIT

Limits results

```SQL
LIMIT 10 -- Take only 10 results
```

## SparQL functions

### COUNT

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

