The easiest way to just say that two things are not the same is to use !=
sign.
select distinct *
where {
?a a ?s.
?b a ?s.
filter (?a!=?b)
}
However, this query is very strange because by just writing:
select distinct *
where {
?a ?p ?s.
}
You are able to extract every distinct ?a
that has a ?p
relation with ?s
. Thus, depending on your use, you have already generated your result set.
If you need to dig deeper, as per your comment:
I have an ontology where objects of type "teams" have a "locatedIn" relationship with their "hometown", and I wish to find all of the possible local derbies.
You need to add more restrictions by adding another triple that relates to the first tripe. For example, in dbpedia, the following query will give you all the teams and their grounds:
select distinct *
where{
?o a dbpedia-owl:SportsTeam.
?o dbpedia-owl:ground ?ground.
}