获取最新记录 [英] To get latest record

查看:66
本文介绍了获取最新记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在一张桌子上,我有一些记录.在这些记录中,有两个具有相似数据的记录,但是两个记录的唯一区别是记录日期.

现在,我要检索这2条记录的最新记录,并跟随其他记录.

对此查询.

在此先感谢
Subhash G.

Hi,

In a table i am having some records. out of those records, two records having simillar data but only difference in that two records is Record date.

Now i want to retrive the latest record of those 2 records and following the other records.

Adcvice a query for this.

Thanks in Advance
Subhash G.

推荐答案

select top 1 * from tablename order by recorddate desc


您需要使用order by子句对结果进行排序.排序顺序将降序,因为您需要最新的排序.因此查询将类似于:

You need to sort the results using order by clause. The sort order will be descending as you need the newest at the top. So the query will be like:

SELECT * FROM TABLE_NAME ORDER BY DATE_COLUMN_NAME DESC



这将为您提供所有结果.现在使用top子句过滤行.

希望这会有所帮助!



This will give you all the results. Now filter the rows using top clause.

Hope this helps!


Subhash,

查找我的查询:
Hi Subhash,

Find my query:
select * from tablename where recorddate =(select max(recorddate) from tablename)



这只会返回1行.我认为这对您有帮助.

干杯

-Sugato



This will return only 1 row.I think this will help you.

Cheers

-Sugato


这篇关于获取最新记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆