[英]Show most recent result only from GROUP BY
I need to show only the most recent entries in the results I know I should do a join or inner join but cannot seem to get that to work properly. 我只需要显示结果中的最新条目即可,我知道我应该进行联接或内部联接,但似乎无法正常工作。 I am sure it is something simple I am over looking. 我敢肯定,这很简单。
$result = mysql_query("SELECT * FROM form_2 GROUP BY jobname");
I am looking to get only the most resent result by jobname. 我希望按职位名称获取最讨厌的结果。
Right Now it displays the first entries with the same jobname I need the most recent. 现在,它显示与我需要的最新工作名称相同的前几个条目。 When someone added a comment the jobname is the consistent. 当有人添加评论时,职位名称是一致的。 And I need to just display the most recent entire to show the most recent comment added with that jobname. 我只需要显示最新的整体,以显示该工作名称添加的最新评论。
Try this: 尝试这个:
select form_2.*
from form_2
inner join (
select jobname, max(awardedcon) as max_value
from form_2
group by jobname
) as a on form_2.jobname=a.jobname and form_2.awardedcon=a.max_value
I am assuming that awardedcon
is an increasing value for each jobname
( ie the most recent entry for each jobname
will have the biggest awardedcon
value) 我假设awardedcon
是每个值的增加jobname
( 即每个最新的条目jobname
将有最大的awardedcon
值)
Hope this helps you. 希望这对您有所帮助。
SELECT jobname,
max(awardedcon) as last_awardedcon
FROM form_2
GROUP BY jobname
ORDER BY last_awardedcon DESC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.