I have an entity class

```
public class TeklaEventE {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
    private Integer projectId;
    private Integer drawingId;
    private Integer userId;
    private String eventType;
    private LocalDateTime eventDate; 
    private LocalDateTime modifiedDate; 
    private String projectName;
    private String userName;
    private transient int noOfUser;    
    // getter setter
}

```

I want to get `* , COUNT(DISTINCT userId)` by grouping `projectId` by ordering `eventDate`

I tried following queries

1. `SELECT *,COUNT(DISTINCT userId) as noOfUser FROM teklaevent group by projectId order by eventDate desc;`
it gives correct count but it first run `group by` then `order by` but i need latest row who has distinct `projectId`. Then i try second query as suggested
2. `select * FROM TeklaEvent where id in (select max(id) FROM TeklaEvent group by projectId) order by eventDate desc;` It gives perfect row what I need because `eventDate` is always current date. But as I try to get `COUNT(DISTINCT userId)` from below query.
3. `select *,COUNT(DISTINCT userId) as noOfUser FROM TeklaEvent where id in (select max(id) FROM TeklaEvent group by projectId) order by eventDate desc;` it fails to give me correct result.

How to do this in a single query?