I am writing a JOOQ query. For example I have this table
| ID | Name | Status |
|---|---|---|
| 1 | Erick | Single |
| 2 | James | Single |
| 3 | Erick | Single |
| 4 | Erick | Married |
I want to check if all "Erick" is "Single". In this case, it should return false.
I tried this JOOQ query and I guess it works:
return !context.fetchExists(
context.selectFrom(TABLE_NAME)
.where(TABLE_NAME.NAME.eq("Erick"),
TABLE_NAME.STATUS.ne("Single"))
));
Is there a more elegant approach? My goal is to immediately return if the pointer encounters an "Erick" that is "Married" and at the same time, the query is readable.