title: How can I display a specific class for an individual with SPARQL?
body: <p>I used Protege to create a small ontology.</p>
  
  <p>I start with a class A, a class B, and a class C. Class C contains the subclasses x, y and z. The individuals populating this ontology fall under two classes: the first class is either A or B, the second one is one of the subclasses of C.</p>
  
  <p>I want to retrieve all individuals which have a property H, and which are also either part of class x or y, but not z. I have been able to do that with the following query:</p>
  
  <pre><code>SELECT ?individual
      WHERE {?individual ont:hasH ?individual.
          FILTER(NOT EXISTS { ?individual rdf:type ont:z } )}
  </code></pre>
  
  <p>(ont is the prefix for my ontology)</p>
  
  <p>This query does what I want. But for these individuals, I would also like to know whether they are part of class x or y. I've tried changing my query to the following, to no avail:</p>
  
  <pre><code>SELECT ?individual ?class
      WHERE {?individual ont:hasH ?individual.
          FILTER(NOT EXISTS { ?individual rdf:type ont:z } ) ?class rdf:type ont:C}
  </code></pre>
  
  <p>Since x and y belong to class C, what I need to know what the class C of the selected individuals is. How could I do that?</p>
  
  <p>(Please bear in mind that I'm completely new to SPARQL.)</p>