<https://kgdev.net/specifications/sparql11-query/subqueries/#this>
        a                          <https://kgdev.net/ns#Definition> , <https://w3id.org/atomgraph/linkeddatahub#Content> ;
        <http://www.w3.org/1999/02/22-rdf-syntax-ns#value>
                "<div xmlns=\"http://www.w3.org/1999/xhtml\"><h2 id=\"this\">Subqueries</h2>\n\n<p>Subqueries are a way to embed SPARQL queries within other queries, normally to achieve results which cannot otherwise be achieved, such as limiting the number of results from some sub-expression within the query.</p>\n<p>Due to the bottom-up nature of SPARQL query evaluation, the subqueries are evaluated logically first, and the results are projected up to the outer query.</p>\n<p>Note that only variables projected out of the subquery will be visible, or <a href=\"../sparqlDefinition/sparqlQuery/#variableScope\" shape=\"rect\">in scope</a>, to the outer query.</p>\n<h3>Example</h3>\n<p>Data:</p>\n<pre xml:space=\"preserve\"><code class=\"language-turtle\">@prefix : &lt;http://people.example/&gt; .\n\n:alice :name \"Alice\", \"Alice Foo\", \"A. Foo\" .\n:alice :knows :bob, :carol .\n:bob :name \"Bob\", \"Bob Bar\", \"B. Bar\" .\n:carol :name \"Carol\", \"Carol Baz\", \"C. Baz\" .\n</code></pre>\n<p>Return a name (the one with the lowest sort order) for all the people that know Alice and have a name.</p>\n<p>Query:</p>\n<pre xml:space=\"preserve\"><code class=\"language-sparql\">PREFIX : &lt;http://people.example/&gt;\nPREFIX : &lt;http://people.example/&gt;\nSELECT ?y ?minName\nWHERE {\n  :alice :knows ?y .\n  {\n    SELECT ?y (MIN(?name) AS ?minName)\n    WHERE {\n      ?y :name ?name .\n    } GROUP BY ?y\n  }\n}\n</code></pre>\n<p>Results:</p>\n<table class=\"resultTable table table-striped\">\n   <tbody>\n      <tr>\n         <th colspan=\"1\" rowspan=\"1\">y</th>\n         <th colspan=\"1\" rowspan=\"1\">minName</th>\n      </tr>\n      <tr>\n         <td colspan=\"1\" rowspan=\"1\">:bob</td>\n         <td colspan=\"1\" rowspan=\"1\">\"B. Bar\"</td>\n      </tr>\n      <tr>\n         <td colspan=\"1\" rowspan=\"1\">:carol</td>\n         <td colspan=\"1\" rowspan=\"1\">\"C. Baz\"</td>\n      </tr>\n   </tbody>\n</table>\n\n<p>This result is achieved by first evaluating the inner query:</p>\n<pre xml:space=\"preserve\"><code class=\"language-sparql\">SELECT ?y (MIN(?name) AS ?minName)\nWHERE {\n  ?y :name ?name .\n} GROUP BY ?y\n</code></pre>\n<p>This produces the following solution sequence:</p>\n<table class=\"resultTable table table-striped\">\n   <tbody>\n      <tr>\n         <th colspan=\"1\" rowspan=\"1\">y</th>\n         <th colspan=\"1\" rowspan=\"1\">minName</th>\n      </tr>\n      <tr>\n         <td colspan=\"1\" rowspan=\"1\">:alice</td>\n         <td colspan=\"1\" rowspan=\"1\">\"A. Foo\"</td>\n      </tr>\n      <tr>\n         <td colspan=\"1\" rowspan=\"1\">:bob</td>\n         <td colspan=\"1\" rowspan=\"1\">\"B. Bar\"</td>\n      </tr>\n      <tr>\n         <td colspan=\"1\" rowspan=\"1\">:carol</td>\n         <td colspan=\"1\" rowspan=\"1\">\"C. Baz\"</td>\n      </tr>\n   </tbody>\n</table>\n\n<p>Which is joined with the results of the outer query:</p>\n<table class=\"resultTable table table-striped\">\n   <tbody>\n      <tr>\n         <th colspan=\"1\" rowspan=\"1\">y</th>\n      </tr>\n      <tr>\n         <td colspan=\"1\" rowspan=\"1\">:bob</td>\n      </tr>\n      <tr>\n         <td colspan=\"1\" rowspan=\"1\">:carol</td>\n      </tr>\n   </tbody>\n</table></div>"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> ;
        <http://www.w3.org/ns/prov#wasDerivedFrom>
                <https://www.w3.org/TR/sparql11-query/#subqueries> ;
        <https://schema.org/name>  "Subqueries" .

<https://kgdev.net/specifications/sparql11-query/subqueries/>
        a       <https://www.w3.org/ns/ldt/document-hierarchy#Item> ;
        <http://www.w3.org/1999/02/22-rdf-syntax-ns#_1>
                <https://kgdev.net/specifications/sparql11-query/subqueries/#this> ;
        <http://purl.org/dc/terms/modified>
                "2023-07-10T16:04:58.582Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> ;
        <http://purl.org/dc/terms/title>
                "Subqueries" ;
        <http://rdfs.org/sioc/ns#has_container>
                <https://kgdev.net/specifications/sparql11-query/> ;
        <http://www.w3.org/ns/prov#wasDerivedFrom>
                <https://www.w3.org/TR/sparql11-query/#subqueries> ;
        <http://xmlns.com/foaf/0.1/primaryTopic>
                <https://kgdev.net/specifications/sparql11-query/subqueries/#this> .
