Код: Выделить всё
| ID | MESSAGE | RECIPIENT_ID | ULTIMATE_PARENT_ID | SENT_AT |
| 1 | Blah. | 10 | 1 | 2024-09-10T10:10:00 |
| 2 | Blah2 | 10 | 2 | 2024-09-11T12:20:00 |
| 3 | Blah3 | 10 | 1 | 2024-09-12T15:10:00 |
| 4 | Blah4 | 10 | 1 | 2024-09-13T16:10:00 |
По сути, запрос из приведенной выше таблицы должен отправлять обратно:
Код: Выделить всё
| ID | MESSAGE | RECIPIENT_ID | ULTIMATE_PARENT_ID | SENT_AT |
| 2 | Blah2 | 10 | 2 | 2024-09-11T12:20:00 |
| 4 | Blah4 | 10 | 1 | 2024-09-13T16:10:00 |
Код: Выделить всё
@Query(value = "SELECT dm FROM " +
"(SELECT DISTINCT d.ultimateParentId from DirectMessage d WHERE dm.recipient.id = :recipientId) DirectMessage dm " +
"ORDER BY dm.sentAt DESC", nativeQuery = true)
Page findPaginatedDirectMessagesByRecipientIdGroupByUltimateParentId(Long recipientId, Pageable pg);
Подробнее здесь: https://stackoverflow.com/questions/791 ... returned-f