An introduction to RDF querying in SPARQL

Zwifi
2,844 views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content
Previous: Grouping

Result set modifiers

Ordering the results

Ordering lexicographically
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
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Ordering by birth year
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)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Removing duplicates

Who are the actors who played a role?
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.
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Who are the actors who played a role?
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.
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content