简体   繁体   English

选择尚未在Mysql之前查询的记录

[英]Select records that hasn't been query before Mysql

How can I retrieve only records that haven't been queried before? 如何只检索以前未查询过的记录?

For example: 例如:

If I have 3 record in my table: 如果我的表中有3条记录:

  • Record 1 记录1
  • Record 2 记录2
  • Record 3 记录3

And I make a query like 我像这样查询

`SELECT * FROM TABLE` 

I will get the three record above. 我会得到上面的三个记录。 If I inserted three more records and I make the query again I just want to see: 如果我再插入三个记录,然后再次进行查询,我只想看到:

  • Record 4 记录4
  • Record 5 记录5
  • Record 6 记录6

Is there a way to make this possible? 有没有办法使之成为可能?

Thank you! 谢谢!

A reliable approach is adding some sort of flag to the table that indicates whether the row has been "read" before, and query as follows: 一种可靠的方法是在表中添加某种标志,以指示该行之前是否已被“读取”,并进行如下查询:

START TRANSACTION;

SELECT * FROM my_table WHERE read_flag = 0 FOR UPDATE;

UPDATE my_table SET read_flag = 1 WHERE id = my_table.id;

COMMIT;

Note that this requires the InnoDB engine. 请注意,这需要InnoDB引擎。

Which programming langauge are u using? 您正在使用哪种编程语言?

You could save the id of "Record3", and then query: 您可以保存ID为“ Record3”,然后查询:

select * from table where id > (id_from_record_3)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 选择某个日期之前或之后尚未使用的MySQL记录 - Select a MySQL record that hasn't been used before or past a certain date 如果未达到限制,是否可以使用单个MySQL查询选择不同的行,然后选择非不同的行? - Can I use a single MySQL query to select distinct rows and then non-distinct rows if a limit hasn't been reached? 加速/优化 MySQL 语句 - 查找之前未选择的新行 - Speed-up/Optimise MySQL statement - finding a new row that hasn't been selected before PHP和MySQL:从数据库中选择未刷新超过2分钟的帐户 - PHP & MySQL: Select account from database which hasn't been refreshed for more than 2 minutes 如何选择一条记录,更新它,并确保它没有被更新? - How to SELECT a record, UPDATE it and be sure it hasn't been updated in the mean? 如果未更新另一行,则更新单个mysql行 - Update a single mysql row if another row hasn't been updated 一个表中未填充的Mysql结果 - Mysql Results from one table that hasn't been populated in another MySQL选择公司尚未提出要约的任务 - MySQL select tasks where company hasn't made an offer MySQL 查询到 select 记录与日期 - MySQL query to select records with date 查询以包括签出表中不存在的内容,并排除未签入的内容 - Query to include what doesn't exist in checkout table AND exclude what hasn't been checked in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM