Diksha Jaiswal
Diksha Jaiswal

Reputation: 43

SPARQL SELECT query not working on Protege for multiple matches

I'm trying to run select queries in protege:

SELECT ?subject WHERE { 
    ?subject uni4:friendof uni4:t3 .                                  
}

Above query gives 'd3' as result.

SELECT ?subject WHERE { 
  ?subject uni4:friendof uni4:t4 .                                 
}

This query gives 'd4' as result.

But when I run the following query I get no results.

SELECT ?subject WHERE {     
    ?subject uni4:friendof uni4:t3 .                                  
    ?subject uni4:friendof uni4:t4
}

Why so? What's wrong here?

Upvotes: 1

Views: 161

Answers (1)

UninformedUser
UninformedUser

Reputation: 8465

Because the last queries asks for subjects that are both friend of t3 and t4.

If you want to have both results returned, UNION is the way to go:

SELECT DISTINCT ?subject WHERE { 
 { ?subject uni4:friendof uni4:t3 }
UNION                                
 { ?subject uni4:friendof uni4:t4 }
}

Or in SPARQL 1.1 you can use VALUES as more compact alternative:

SELECT DISTINCT ?subject WHERE { 
   ?subject uni4:friendof ?friend
   VALUES ?friend { uni4:t3 uni4:t4 }
}

Upvotes: 1

Related Questions