Introduction
The @Query annotation lets you write your own database queries in Java code. It helps when you want to get data in a special way that the usual methods can't do.
You want to find records using a complex condition not covered by method names.
You need to join multiple tables and fetch specific fields.
You want to write a query with sorting or grouping that is not automatic.
You want to update or delete records with a custom query.
You want to optimize performance by writing a precise query.