Let say I have triples of the form
uri:ObjA1 uri:propAA uri:Obj1A .
uri:ObjA1 uri:propAA uri:Obj1B .
uri:ObjA2 uri:propAA uri:Obj1A .
uri:ObjA2 uri:propAA uri:Obj1B .
uri:ObjA2 uri:propAA uri:Obj1C .
Now, what I am trying to do is find all instances that only have values Obj1A and Obj1B for propAA. Basically, the query should return ObjA1 and not ObjA2 because only ObjA1 takes values Obj1A and Obj1B only for propAA. What I have right now is
SELECT * where {
?sub uri:propAA uri:Obj1A .
?sub uri:propAA uri:Obj1B .
FILTER NOT EXISTS {
?sub uri:propAA ?obj .
FILTER((?obj != uri:Obj1A) && (?obj != uri:Obj1B)) .
}
}
Now, this query works. If I don't put the FILTER NOT EXISTS clause, then it returns both ObjA1 and ObjA2. What I am looking for now is to know if there is a better way to write this query? Better would mean, more efficient or more concise (or both).