2012-05-20 33 views
0

我的数组包含了一些元素:使用表中的Where子句

(
    "element 1", 
    "element 2", 
    "element 3" 
) 

我需要查询数据库,并获取存储阵列中的上述数据库中的每一个元素:

select * from table1 where type=? 

我得到了for循环的想法,对于数组,选择查询将根据数组的大小重复执行,这并不是很有用。

任何想法,thanx提前:)

+0

它为什么被标记为'iOS'? – rishi

回答

2

使用IN operator

select * from table1 where type in ('element1', 'element2'); 
+0

嗨,thanx为您的答复,但在我的情况下''element1','element2'存储在'NSMutableArray',所以我怎么能将'NSMutable'数组转换成像这样的字符串? – Luca

+0

您应该使用参数化查询:'select * from table where type(?,?)'then [将它们绑定到您的值](http://www.sqlite.org/c3ref/bind_blob.html) – beerbajay

2

你的意思是这样

select * from table1 where type in ('type1', 'type2', 'type3')