SQL查询最新更新的记录 [英] Sql query for latest updated record

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

问题描述

我有一张桌子,其中对于一个蠕虫产品,有几个脚架.所以我想获取每个产品的最新更新记录.我正在使用oracle.

I have a table in which for a perticular product several recods exixts. So i want to fetch latest updated record with every product. I am using oracle .

推荐答案

默认情况下,Oracle不知道最新记录是什么.好的,老实说,它确实可以,但是这些信息不容易使用,尤其是长时间使用.

因此,您应该做的第一件事是在表中定义一列,该列定义记录的插入和/或更新顺序.为了使程序不可见,您可以使用例如BEFORE触发器来设置相关数据.一种简单的方法是在表中定义一个DATE列,而INSERT触发器会将插入日期标记在该行上.当然,您也可以通过在表定义中使用DEFAULT约束来实现此目的(但是,这不是更新的可行解决方案).

现在,如果您已将日期标记在行上,则可以在查询中使用该列.

请记住,默认分辨率为1秒,因此在您的情况下这可能可靠,也可能不可靠.

另一种选择是使用序数,这很精确.
By default, Oracle does not know what is the latest record. Okay, to be honest, it does but this information isn''t easily usable especially for longer periods of time.

So the first thing you should do is to define a column in your table which defines the insert and/or update order of the records. To be invisible to the programs, you can use for example BEFORE trigger to set the relevant data. One easy way is to define a DATE column to the table and an INSERT trigger would stamp the insertion date to the row. Of course you can also achieve this by using a DEFAULT constaint in the table defintion (however, that is not a feasible solution for updates).

Now if you have stamped the date to the row, you can use that column in your query.

Remember that the default resolution is 1 second so this may or may not be reliable in your scenario.

Another alternative is to use an ordinal number, which would be precise.


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

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