如何在sqlite数据库中删除多行 [英] How to delete multiple rows in sqlite database

查看:505
本文介绍了如何在sqlite数据库中删除多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sqlite数据库中有一个表,其中包含61249行,因为我只需要873行,其余的行必须删除。我不幸地使用循环概念尝试了它。我正在使用dbbrowser sqlite访问此数据库。我们不能在这里使用循环。

I have a table in sqlite database which consists of 61249 rows in that i just need 873 rows rest of the rows have to be deleted. I tried it by using loops concept but unfortunately. I am using dbbrowser sqlite to access this database. we cant use loops here can any one solve this.

推荐答案

如果您知道如何从表中选择873行,则应该做这样的事情。以下是删除所有选定行的方法,在本示例中,所有行除id介于3和5之间的行...

if you know how to select your 873 rows from your table you should do something do like this. Here is how to delete all rows except selected, in this example all rows except those where id is between 3 and 5...

 DELETE FROM table1
 WHERE id NOT IN (SELECT id FROM table1 WHERE id BETWEEN 3 AND 5);

这里是SQL Fiddle,它用来查看 http://sqlfiddle.com/#!7/3d657/1

Here is SQL Fiddle for that to see how that look like http://sqlfiddle.com/#!7/3d657/1

这篇关于如何在sqlite数据库中删除多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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