在 Sqlite 中更新查询 [英] Update query in Sqlite

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

问题描述

我试图在 sqlite 中只更新 10 条按日期排序的记录.

I was trying to update only 10 records sorted by date in sqlite.

我正在使用此查询,但无法继续进一步获取限制异常.

I am using this query but not able to proceed further getting exception at limit.

UPDATE TABLENAME  SET COLUMMANGE = 'VALUE' WHERE  1  LIMIT 10 ORDER BY COLUMNNAME ASC

推荐答案

我假设您的表中有一个名为 ID 的字段,基于它,您应该按照以下方式查询更新 10 条最新记录,

I am assuming that you have one field named ID in your table, based on it your query to updated 10 latest record should be done following way,

UPDATE TABLENAME  SET COLUMMANGE = 'VALUE' WHERE 
ID in ( SELECT ID from TABLENAME ORDER BY COLUMNNAME DESC LIMIT 10 );

这里的内部查询将从表中选择 10 个最新的记录 ID.这些 ID 将传递给外部更新查询.

Here inner query will select 10 latest record id from the table. These Ids will be passed to outer Update query.

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

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