查询以仅选择新添加的记录 [英] Query to select newly added records only

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

问题描述

由于我是mysql的新手,所以让我清除这个疑问.如何编写查询以仅查找/选择最新添加的记录?

As I am new to mysql, let me clear this doubt. how to write a query to find/select the latest added records only?

示例: 考虑一个表,该表每天添加一定数量的记录.现在该表包含1000条记录.总共取出了1000条记录以提高性能.有时在表中添加了100条记录.现在,我只想从1100中取剩下的100做一些操作.怎么做?

Example: Consider a Table, which is daily added certain amount of records. Now the table contain 1000 records. And the total 1000 records are taken out for some performance. After sometimes table is added 100 records. Now I would like take the remain 100 only from the 1100 to do some operation. How to do it?

(仅作为示例,我给出了数字,但最初我不知道最后更新的计数和新添加的计数)

(For example only, I have given the numbers, But originally I don't know the last updated count and the newly added)

此处,我的表包含三列Sno,时间和数据. Sno被索引为主键的地方.

Here My table contain three columns Sno, time, data. where Sno is indexed as primary key.

样品表:

| sno | time                | data    |

|   1 | 2012-02-27 12:44:07 |     100 |

|   2 | 2012-02-27 12:44:07 |     120 |

|   3 | 2012-02-27 12:44:07 |     140 |

|   4 | 2012-02-27 12:44:07 |     160 |

|   5 | 2012-02-27 12:44:07 |     180 |


|   6 | 2012-02-27 12:44:07 |     160 |

|   7 | 2012-02-28 13:00:35 |     100 |

|   8 | 2012-03-02 15:23:25 |     160 |

推荐答案

使用'ON UPDATE CURRENT_TIMESTAMP'选项添加TIMESTAMP字段,您将能够找到最后添加或最后编辑的记录.

Add TIMESTAMP field with 'ON UPDATE CURRENT_TIMESTAMP' option, and you will be able to find last added or last edited records.

自动初始化和更新TIMESTAMP .

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

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