Match where the value is NULL in SPARQL

I have the following SPARQL query:

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

With results similar to the following:

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

I also want the label without to ?imgalso match the elements that ?imghave NULLie. I need the following results:

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

If I use my previous query, the result for label2will not be displayed?

How do I modify my query to include such strings as well?

+4
source share
1 answer

Use OPTIONAL:

select ?label ?img where {
?uri rdfs:label ?label.
 OPTIONAL { ?uri vtio:hasImage ?img. }
}
+7
source

All Articles