Reputation: 331
I would like to know how to express the following question in sparql:
"Give me the parents whose every child goes to MIT"
More generally, I would like to know what are the limits of query sparql please? What kinds of questions with answers in database cannot be formulated as sparql, please?
Thank you for your help
Upvotes: 2
Views: 192
Reputation: 2582
Your question involves quantification, and is one example of things that cannot be expressed as one query in regular SPARQL 1.0. (It may be expressed in SPARQL 1.1 as shown in Jeen Broekstra's answer, or as an OWL class.)
Many SPARQL 1.0 implementations, though, have developped extensions to handle quantification. A commercial example is Intellidimension Semantics Platform, which would give you something like:
SELECT ?parent
WHERE { ?child :hasParent ?parent FORALL(?child){ ?child :hasSchool "MIT" } }
An academic example is SPARQLog from Oxford University Computing Lab. I am not aware that this system is available as an easy download, but the paper is freely available and provides insight into the difficulties of implementing quantification for SPARQL.
As for your question about the limits of SPARQL, it is too general to answer in a few words, but here is a link to a relevant paper, again as far as SPARQL 1.0 is concerned: Semantics and Complexity of SPARQL
Upvotes: 4
Reputation: 22052
You can express this using a negated existential quantification. Like this:
SELECT ?parent
WHERE { ?parent a :Parent .
FILTER NOT EXISTS {
?c :childOf ?parent .
?c :enrolledIn ?school .
FILTER (str(?school) != "MIT")
}
}
This query asks for all parents who do not havy any child that is enrolled in a school different from MIT.
Upvotes: 5
Reputation: 1491
For the specific question you can read up on relational division. Alternatively, you can find all the children who do not go to MIT, find their parents, and remove those parents from the list of all parents.
Sorry, can't help with SPARQL's limits.
Upvotes: 0