Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Match where 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 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?

like image 460
Do Thanh Tung Avatar asked Dec 17 '13 20:12

Do Thanh Tung


1 Answers

Use OPTIONAL:

select ?label ?img where {
?uri rdfs:label ?label.
 OPTIONAL { ?uri vtio:hasImage ?img. }
}
like image 138
Jeen Broekstra Avatar answered Oct 02 '22 02:10

Jeen Broekstra