64

Is there a way to mix LIKE operator with IN ? Something Like

SELECT Id FROM Account WHERE Name LIKE IN:nameList

Where nameList is list of String? Is this is possible ? (I can make a dynamic query by doing OR with all the elements, but was looking for a more elegant way to do this)

1
  • You can't do a LIKE with IN. You have to use the OR query. Or maybe you can use SOSL. Jun 6, 2013 at 8:27

1 Answer 1

95

No, but you can query like this which does the same thing as what you're trying to do:

String[] filters = new String[]{'acme%','ib%'};
List<Accounts> accs = [SELECT Id, Name FROM Account WHERE Name LIKE :filters];
8
  • That's a neat solution to the problem.
    – Doug B
    Jun 6, 2013 at 8:56
  • ahhh really neat. Somehow thought IN can only operator on collections
    – Avidev9
    Jun 6, 2013 at 8:56
  • Yea this method is a huge time saver. Also, with using the OR option, you run into the query length limitation eventually.
    – drakored
    Jun 6, 2013 at 8:59
  • NIce solution, +1! Jun 6, 2013 at 11:14
  • fantastic solution!! my upvote for this...I thought there would be no option to do a like for multiple strings. Fortunately i found this. Thanks drakored!!
    – Bforce
    Jul 27, 2014 at 21:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .