An introduction to RDF querying in SPARQL
Zwifi
20.8K views
Result set modifiers
Ordering the results
Ordering lexicographically
1
2
3
4
5
6
7
8
9
PREFIX yaco: <https://www.irit.fr/recherches/MELODI/ontologies/cinema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?name
WHERE {
?actor rdf:type yaco:Actor;
rdfs:label ?name;
yaco:birthYear ?year.
} ORDER BY ?name
1
@prefix yaco: <https://www.irit.fr/recherches/MELODI/ontologies/cinema#> .
Ordering by birth year
1
2
3
4
5
6
7
8
9
PREFIX yaco: <https://www.irit.fr/recherches/MELODI/ontologies/cinema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?name
WHERE {
?actor rdf:type yaco:Actor;
rdfs:label ?name;
yaco:birthYear ?year.
} ORDER BY DESC(?year)
1
@prefix yaco: <https://www.irit.fr/recherches/MELODI/ontologies/cinema#> .
Removing duplicates
Who are the actors who played a role?
1
2
3
4
5
6
7
8
9
10
PREFIX yaco: <https://www.irit.fr/recherches/MELODI/ontologies/cinema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?name
WHERE {
?actor rdf:type yaco:Actor;
rdfs:label ?name;
yaco:playsRole ?role;
yaco:birthYear ?year.
}
1
@prefix yaco: <https://www.irit.fr/recherches/MELODI/ontologies/cinema#> .
Who are the actors who played a role?
1
2
3
4
5
6
7
8
9
10
PREFIX yaco: <https://www.irit.fr/recherches/MELODI/ontologies/cinema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT ?name
WHERE {
?actor rdf:type yaco:Actor;
rdfs:label ?name;
yaco:playsRole ?role;
yaco:birthYear ?year.
}
1
@prefix yaco: <https://www.irit.fr/recherches/MELODI/ontologies/cinema#> .
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.