如何获取最新行mysql的列

时间:2013-07-31 06:39:19

标签: mysql groupwise-maximum

以下查询对我来说没问题,但 message_content 列中的内容属于表 al_messages 的第一行。我怎样才能获得最新一行的内容?

SELECT a.CONVERSATION_ID, 
       a.CREATOR_ID, 
       c.SCREEN_NAME       AS creator_screen_name, 
       c.FIRST_NAME        AS creator_first_name, 
       c.LAST_NAME         AS creator_last_name, 
       Count(d.MESSAGE_ID) AS messages_count, 
       MESSAGE_CONTENT 
FROM   AL_CONVERSATIONS a 
       INNER JOIN AL_SUBJECTS b 
               ON a.SUBJECT_ID = b.SUBJECT_ID 
       INNER JOIN AL_MEMBERS c 
               ON a.CREATOR_ID = c.MEMBER_ID 
       INNER JOIN AL_MESSAGES d 
               ON a.CONVERSATION_ID = d.CONVERSATION_ID 
WHERE  a.SUBJECT_ID = 301 
       AND b.CREATOR_ID = 17 
GROUP  BY a.CONVERSATION_ID 

查询结果:

enter image description here

0 个答案:

没有答案