How do I write a query to fetch records which is distinct in one column and desc order in another column.
I was able to fetch the records using the following statement.
select * from
(select * from t1
where id=14
order by ttimestamp desc) as h
group by hnumber
order by ttimestamp desc
But when I tried the same in JPA.
SELECT m from
(SELECT m from t1 m
WHERE m.user = :user
ORDER BY m.tTimestamp DESC) as h
GROUP BY m.hNumber
ORDER BY m.tTimestamp DESC
I got an error saying syntax error.
Exception Description: Syntax error parsing [SELECT m from (SELECT m from t1 m WHERE m.user = :user ORDER BY m.tTimestamp DESC) as h GROUP BY m.hNumber ORDER BY m.tTimestamp DESC].
The right parenthesis is missing from the sub-expression.
An identification variable must be provided for a range variable declaration.
The query contains a malformed ending.
Any help is appreciated.