Question

I have the following SPARQL query:

SELECT ?label ?img 
WHERE
{
  ?uri rdfs:label ?label .
  ?uri vtio:hasImage ?img .
}

With results like the following:

label | img
-------------
label | link1
labe2 | link2
…

I also want the label without ?img also matched i.e. entries where ?img is NULL i.e. I want results like the following:

label  | img
--------------
label1 | link1
label2 |
label3 | link3
…

If I use my earlier query a result for label2 will not be shown?

How do I modify my query to also include rows like this?

Was it helpful?

Solution

Use OPTIONAL:

select ?label ?img where {
?uri rdfs:label ?label.
 OPTIONAL { ?uri vtio:hasImage ?img. }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top