[英]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条记录:
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:
如果我再插入三个记录,然后再次进行查询,我只想看到:
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.