title: Spring Data JPA Distinct - Return results from a single column
body: <p>I have some data that contains a <code>STATE</code> field (String/Text) that defines what state a given request is currently in (e.g. pending, approved denied etc.) and to get all the unique values from that column I can run the following TSQL query</p>
  
  <p><code>SELECT DISTINCT STATE FROM CALLOUT_REQUEST</code></p>
  
  <p>where <code>CALLOUT_REQUEST</code> is my table name and <code>STATE</code> being the field which returns something like:</p>
  
  <p>STATE</p>
  
  <ul>
  <li>approved</li>
  <li>denied</li>
  <li>pending</li>
  <li>...</li>
  </ul>
  
  <p>However I don't understand how I would turn that into a query in my repository as it seems I need a "by" statement or some other filter mechanism which i can get the <code>STATE</code> based on?</p>
  
  <p>What I am looking to return - as shown in the raw TSQL query above - is some kind of List or Array object which contains all the unique/distinct values in all of the <code>STATE</code> fields.</p>
  
  <p>So in pseudo code i think i am looking for something like this:</p>
  
  <p><code>String[] states = repository.findDisinctState();</code></p>
  
  <p>where <code>findDistinctState()</code> would then return an array of sorts.</p>
  
  <p>Hope that makes sense - I am very new to Java and Spring in general so I think I am missing some conceptual knowledge to utilise the above.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>The 'state' concept is closed so i could implement that as an enum - only problem is i dont know how to do that :) Ill look into how i can do that as i think it fits perfectly with what i am trying to achieve.</p>
  
  <p>The List i get from the query provided is intended to be used to get a count of all the occurrences. I had this code before to get a total count for each of the 'states':  </p>
  
  <pre><code>Map stats = new HashMap();
  String[] states = {"approved", "denied", "pending", "deactivated"};
  for (int i = 0; i &lt; states.length; i++) {
      stats.put(states[i], repository.countByState(states[i]));
  }
  </code></pre>
  
  <p>Am i correct in understanding that the states <code>Array</code> that i have in the above code snippet could be turned into an enum and then i dont even need the custom <code>@Query</code> anymore?</p>