Skip to content
Advertisement

Need Help Converting a SQL Query to JPQL

So far, Spring’s JPA repositories have sufficed for me, but now I need a custom query. I have struggled with this for a day trying to learn more about SQL, joins, etc and came up with a native MySQL query which (I think) does what I want: I want to find all the latest of each “product” with a unique url. Example:

This is the native MySQL query I came up with:

My attempts to transform this to JPQL in order to use them an @Query annotation seem rather embarrassing so I won’t even bother posting them here 😀 Can someone help me?

Advertisement

Answer

Convert your SQL query to the form:

It is JPQL-compatible – see Subqueries – EXISTS Expressions.

Or you may use the same idea in >= ALL (..) form.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement