Question: I'm using an ebean query in the play! framework to find a list of records based on a distinct column. It seems like a pretty simple query but the problem is the ebean method setDistinct(true) isn't actually setting the query to distinct.

My query is:

```
List<Song> allSongs = Song.find.select("artistName").setDistinct(true).findList();

```

In my results I get duplicate artist names.

From what I've seen I believe this is the correct syntax but I could be wrong. I'd appreciate any help. Thank you.

Answer: 
According to [issue #158: Add support for using setDistinct (by excluding id property from generated sql)](https://github.com/ebean-orm/avaje-ebeanorm/issues/158) on the Ebean bug tracker, the problem is that an ID column is added to the beginning of the select query implicitly. That makes the distinct keyword act on the ID column, which will always be distinct.

This is supposed to be fixed in Ebean 4.1.2.
As an alternative you can use a native SQL query (SqlQuery).
The mechanism is described here:
<https://ebean-orm.github.io/apidocs/com/avaje/ebean/SqlQuery.html>

This is from the documentation:

```
public interface SqlQuery
extends Serializable
Query object for performing native SQL queries that return SqlRow's.
Firstly note that you can use your own sql queries with entity beans by using the SqlSelect annotation. This should be your first approach when wanting to use your own SQL queries.

If ORM Mapping is too tight and constraining for your problem then SqlQuery could be a good approach.

The returned SqlRow objects are similar to a LinkedHashMap with some type conversion support added.

// its typically a good idea to use a named query
// and put the sql in the orm.xml instead of in your code

    String sql = "select id, name from customer where name like :name and status_code = :status";

    SqlQuery sqlQuery = Ebean.createSqlQuery(sql);
    sqlQuery.setParameter("name", "Acme%");
    sqlQuery.setParameter("status", "ACTIVE");

    // execute the query returning a List of MapBean objects
    List<SqlRow> list = sqlQuery.findList();

```