title: how to get unique row in sql from one column which same value in JPA?
body: <p>I have a contract which has 2 different names but has the same number, and I really want to get only one result which that phone number show up for my result though their name is different </p>
  
  <p>example, in my database I have a column called name and phoneNumber :</p>
  
  <pre><code>1. name : John, phoneNumber: 123;
  2. name : Dion, phoneNumber: 123;
  </code></pre>
  
  <p>I really want to get the result only one which only shows the new one and unique, I could implementation it by <code>SELECT DISTINCT .....</code> so I will only get unique, I was trying <code>SELECT DISTINCT name, phoneNumber FROM Contacts*</code></p>
  
  <p>but the result show those data because they have a different name, I really the result only show up the one only which latest in database</p>
  
  <p>I have DTO( DATA TRANSFER OBJECT) like this </p>
  
  <pre><code>public ContactsDTO {
     private String name;
     private String phoneNumber;
  }
  </code></pre>
  
  <p>I really when I use JPA to get data I could convert that DTO to be Model, it gonna something like this : </p>
  
  <pre><code>[Contact(name="John", phoneNumber="123")];
  </code></pre>
  
  <p>i was using JPA like this 
  List findDistinctByPhoneNumber();
  but it is error, </p>
  
  <p>and when i use</p>
  
  <pre><code>@Query("SELECT DISTINC new map(C.name as name, C.phoneNumber as phonenumber) from Contact C")
  List&lt;Contact&gt; findDistnctByPhoneNumber();
  </code></pre>
  
  <p>the result of that is like this 
  <code>[{name: "John", phone number:"123"}]</code>
  that is the only array of the object inside that array, I do love yo get the model which I something like this : </p>
  
  <pre><code> [Contact(name="John", phoneNumber="123")];
  </code></pre>