Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql SQL或Spring数据:选择一个表中的行,并按另一个表的属性排序_Mysql_Spring_Hibernate_Spring Boot - Fatal编程技术网

Mysql SQL或Spring数据:选择一个表中的行,并按另一个表的属性排序

Mysql SQL或Spring数据:选择一个表中的行,并按另一个表的属性排序,mysql,spring,hibernate,spring-boot,Mysql,Spring,Hibernate,Spring Boot,我使用的是带有Spring数据的Spring Boot。我有两个表:Chat和Messages,它们之间没有任何关系 Message表有一个名为chatId的属性,我可以通过他的id属性来匹配相应的Chat 因此,我的问题是:如何获取所有聊天,并使用Spring Data

我使用的是带有Spring数据的Spring Boot。我有两个表:
Chat
Messages
,它们之间没有任何关系

Message
表有一个名为
chatId
的属性,我可以通过他的
id
属性来匹配相应的
Chat

因此,我的问题是:如何获取所有
聊天
,并使用Spring Data
原生SQL上次创建的
消息的
属性对每个聊天进行排序

SELECT chat.*       /* !! replace asterisk with fields list */
FROM chat
JOIN message ON chat.id = message.chatid
GROUP BY chat.*     /* specify the same fields list */
ORDER BY MAX(message.creationDate) ASC /* or DESC */