title: SPARQL - how to do a join operation
body: <p>I have a model, where I have 3 classes:</p>
  
  <ol>
  <li>SR - <code>&lt;http://data.sample.com/vocab/StudentRecord&gt;</code></li>
  <li>HCVR - <code>&lt;http://data.sample.com/vocab/HealthCenterVisitRecord&gt;</code></li>
  <li>CR - <code>&lt;http://data.sample.com/vocab/ClassRoom&gt;</code></li>
  </ol>
  
  <p><code>StudentRecord</code> has a property <code>classRoom</code>.</p>
  
  <p><code>HealthCenterVisitRecord</code> has a property <code>studentRecord</code>.</p>
  
  <p>Given a particular <code>ClassRoom</code> URI, how do I find all the <code>StudentRecord</code>s, who are properties of <code>HealthCenterVisitRecord</code>s.</p>
  
  <p>Query that I tried (The initial part of the query fetches the student belonging to a <code>ClassRoom</code>, but the second part is screwed up and I know it):</p>
  
  <pre><code>SELECT ?hcvr
  WHERE {
    ?sr rdf:type &lt;http://data.sample.com/vocab/StudentRecord&gt;.
    ?sr &lt;http://data.sample.com/vocab/classRoom&gt; &lt;http://data.sample.com/resource/ClassRoom/1156&gt;.
    ?sr &lt;http://data.sample.com/vocab/healthCentreVisitRecord&gt; ?hcvr.
  }
  </code></pre>
  
  <p>Another query I tried:</p>
  
  <pre><code>SELECT DISTINCT ?sr WHERE {
    {
    ?sr rdf:type &lt;http://data.sample.com/vocab/StudentRecord&gt;.
    ?sr &lt;http://data.latize.com/vocab/classRoom&gt; &lt;http://data.latize.com/resource/ClassRoom/1156&gt;.
    }
  UNION
    { 
          ?hcvr rdf:type &lt;http://data.sample.com/vocab/HealthCentreVisitRecord&gt;.
          ?hcvr &lt;http://data.sample.com/vocab/studentRecord&gt; ?sr.
      }
  }
  LIMIT 1000
  </code></pre>