I'm studying SPARQL and I have a doubt about queries.
Suppose I have a simple ontology like the following
:Jack a :Worker ; :worksAt :Project1,:Project2
:Bob a :Worker ; :worksAt :Project2,:Project3
:Mike a :Worker ; :worksAt :Project3,:Project1
Now I want to ask for the couple of workers who worked on the same project. If I try something like
SELECT ?x,?y
WHERE
{
?x :worksAt ?p
?y :worksAt ?p
}
What happens is that the query also analyzes cases where ?x and ?y are the same resource, hence I have stuff like [Jack,Jack] in the results.
If I do
SELECT ?x,?y
WHERE
{
?x :worksAt ?p
?y :worksAt ?p
FILTER (?x != ?y)
}
the query works properly, but for very complicated queries I find myself doing hundreds of FILTERs like that one.
Is there a better way to specify that ?x and ?y must be different resources?
Thank you in advance for your answers!