1.5.47.How can I use sub-queries to enable literal values based joins?

What?

Use of subqueries to enable literal values based joins.

Why?

Sophisticated access to literal values via subqueries provides powerful mechanism for enhancing sparql graph patterns via dynamic literal value generation.

How?

Use select list variables from subqueries to produce literal object values in sparql graph patterns.

Example

Assume in the following query, where should be used a sub-query to replace ?app:

SELECT DISTINCT ?r
WHERE
  {
    graph ?g
      {
        ?r nie:url ?url .
      }  .
      ?g nao:maintainedBy ?app .
      ?app nao:identifier "nepomukindexer" .
  }

If it is not sure that ?app is the only, for e.g., the triple ?app nao:identifier "nepomukindexer" can appear in more than one graph, then the query should be changed to:

SELECT DISTINCT ?r
WHERE
  {
    graph ?g
      {
        ?r nie:url ?url .
      }  .
      ?g nao:maintainedBy ?app .
      FILTER (?app = (SELECT ?a WHERE { ?a nao:identifier "nepomukindexer" }))
}

or even shorter:

SELECT DISTINCT ?r
WHERE
  {
   graph ?g
     {
       ?r nie:url ?url .
     }  .
   ?g nao:maintainedBy `(SELECT ?a WHERE { ?a nao:identifier "nepomukindexer" })` .
 }