Search code examples
sparqlturtle-rdfblank-nodes

What is the blank nodes utility in SPARQL queries?


I do not understand what is the difference between this SPARQL query :

SELECT ?first ?last ?workTel
WHERE {
  ?s ab:firstName ?first ;
     ab:lastName ?last .
  OPTIONAL
  {?s ab:workTel ?workTel . }
}

and this one :

SELECT ?first ?last ?workTel
WHERE {
  [] ab:firstName ?first ;
     ab:lastName ?last .
  OPTIONAL
  {[] ab:workTel ?workTel . }
}

they give me two different results, so how is blank nodes working and what is the utility of ?s variable here. Thank's for any reply.


Solution

  • [] is syntax for "new blank node" each time it is used.

    In that example, each [] is a different blank node. The query is much the same as two different variables.

    SELECT ?first ?last ?workTel
    WHERE {
      ?VAR_1 ab:firstName ?first ;
             ab:lastName ?last .
      OPTIONAL
      {?VAR_2 ab:workTel ?workTel . }
    }
    

    No connection is formed between the two parts of the query.