Reputation: 4785
I would like to select all Authority
s where Authority.id
and Authority.top
are equal. While the following could not produce the desired outcome, how to implement it using a named query but not a native one?
@Query("SELECT Authority WHERE Authority.id = Authority.top") // how?
List<Authority> findTop();
Upvotes: 0
Views: 316
Reputation: 19
I think the query is syntactically wrong.
It has to be,
SELECT * FROM Authority WHERE Authority.id = Authority.top
OR you can query the columns of your interest like this,
SELECT Authority.id, Authority.name FROM Authority WHERE Authority.id = Authority.top
Upvotes: 0
Reputation: 26522
Either:
1) Without an alias:
@Query("FROM Authority WHERE id = top")
List<Authority> findTop();
2) With an alias:
@Query("SELECT a FROM Authority a WHERE a.id = a.top")
List<Authority> findTop();
In your case option one is preferrable of course
Upvotes: 1