Search code examples
javasqlselectjdbcibatis

How to SELECT items from from an array (IN clause details)?


I would like to do something in Java (using iBatis, JDBC, etc., really in SQL) like:

SELECT SUM(rowName) FROM myTable WHERE id = [myArrayOfIds]

Where myArrayOfIds can be almost any length. Now I know you can do:

SELECT SUM(rowName) FROM myTable WHERE id IN (x, y, z)

but what happens for longer lists? For example my list could be as little as a few items to hundreds or more items. How can I do this?


Solution

  • I think it depends on your flavour of SQL. For instance, Oracle does not allow more than 1000 values in an IN() list. Other flavours may vary.