Sqlite查询一列中的多个值 [英] Sqlite Query for multiple values in one column

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

问题描述

我想在表中查询字段ID,其中包含诸如1、5、4、11之类的值,这些值将根据选择来自上一屏幕.

I wanted to do query in table for field id with some vales like 1,5,4,11 which will come from previous screen according to selection.

cursor = database.query(tablename,
                    new String[] { "TopName" }, "id =?", new String[]{"2,3"}, null, null, null);

当我这样做时,使用新的String [] {"2"}我得到的游标计数为0,我得到的是我想要的所有id的值,这些id具有字符串数组(如OR)中的值,并且在该列中具有值./p>

When I do like this, I am getting cursor count 0, with new String[]{"2"} I am getting value I want for all ids with values in string array like OR which have value in that column.

推荐答案

您可以像这样使用IN运算符,

You can use the IN operator like this,

cursor = database.query(tablename, new String[] {"TopName"}, "id IN(?,?)", 
                                        new String[]{"2","3"}, null, null, null);

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

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