5

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?

RobV
  • 28,022
  • 11
  • 77
  • 119
Do Thanh Tung
  • 1,223
  • 2
  • 19
  • 30

1 Answers1

9

Use OPTIONAL:

select ?label ?img where {
?uri rdfs:label ?label.
 OPTIONAL { ?uri vtio:hasImage ?img. }
}
Jeen Broekstra
  • 21,642
  • 4
  • 51
  • 73