I'm using the following code:
SELECT * FROM table WHERE Col IN (123,123,222,....)
However, if I put more than ~3000 numbers in the IN
clause, SQL throws an error.
Does anyone know if there's a size limit or anything similar?!!
The maximum number of clauses in a WHERE clause is 40. LONGVARBINARY and LONGVARCHAR columns can be compared to literals of up to 255 characters in length, but cannot be compared using parameters.
From my experience the maximum values is 1000 values in clause IN ('1',....,'1000') , I have 1300 value in my excel sheet,I put them all into IN ,MySQL return only 1000 .
You can specify multiple conditions in a single WHERE clause to, say, retrieve rows based on the values in multiple columns. You can use the AND and OR operators to combine two or more conditions into a compound condition. AND, OR, and a third operator, NOT, are logical operators.
what is the upper limit for predicate WHERE IN in DB2. AFAIK, an SQL statement in DB2 (LUW) can be up to about 2 MiB, so you could in principle have somewhere in the region of 250k terms in the IN clause, allowing 8 characters per term including the comma.
Depending on the database engine you are using, there can be limits on the length of an instruction.
SQL Server has a very large limit:
http://msdn.microsoft.com/en-us/library/ms143432.aspx
ORACLE has a very easy to reach limit on the other side.
So, for large IN clauses, it's better to create a temp table, insert the values and do a JOIN. It works faster also.
There is a limit, but you can split your values into separate blocks of in()
Select * From table Where Col IN (123,123,222,....) or Col IN (456,878,888,....)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With