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)

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

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];
  • That's a neat solution to the problem.
    – Doug B
    Jun 6 '13 at 8:56
  • ahhh really neat. Somehow thought IN can only operator on collections
    – Avidev9
    Jun 6 '13 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 '13 at 8:59
  • NIce solution, +1! Jun 6 '13 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 '14 at 21:14

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