0

My array contains some elements:

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

I need to query the database, and fetch for every single element stored in the array above in the database:

 select * from table1 where type=?

I got the idea of a for loop, for the array, and the select query will be repeated depending on the size of the array, which is not so useful.

Any thoughts, thanx in advance :)

0

2 Answers 2

2

Use the IN operator:

select * from table1 where type in ('element1', 'element2');
2
  • Hi, thanx for your reply, but in my case 'element1', 'element2' are stored in a NSMutableArray, so how can i convert the NSMutable array into a String like so ?
    – Luca
    Commented May 20, 2012 at 12:45
  • You should be using a parameterized query: select * from table where type in (?, ?) then bind them to your values
    – beerbajay
    Commented May 20, 2012 at 12:49
2

Do you mean something like

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

?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.