Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: is there a limit to the entries of an "IN" clause? [duplicate]

Tags:

sql

mysql

Possible Duplicate:
MySQL number of items within “in clause”
In mysql or postgres, is there a limit to the size of an IN (1,2,n) statement?

I build an "IN" list dynamically and I was wondering if there is a limit to the size of the IN clause in mysql.

SELECT foo FROM bar WHERE bar_key IN ('prod1', 'prod2', 'prod50', ...'last prod')

I imagine there is a limit to the total length of a SQL statement but I can't find it in the manual.

I do know that an alternative is to build a temp table and join with it, though I'm not sure where the performance tradeoff exists if I have to execute many INSERT statements. Of course if I could populate the temp table with a single INSERT that would be fast, but that's not possible in my case.

So my first question is what are the mysql limits and I'd appreciate if you can point me to relevant pages in the manual.

like image 285
David Avatar asked Jan 10 '12 18:01

David


People also ask

Is there any limit on in clause in MySQL?

In mysql, you should be able to put as many values in the IN clause as you want, only constrained by the value of "max_allowed_packet". Show activity on this post. Show activity on this post. In the provided answer, it is clear that there is no official limit in the specs, but it rather depends on your DBMS config.

How many values can be passed in in clause in SQL?

In Oracle we can't include more than 1000 values in the “IN” clause.

Can we use limit in subquery?

Hi, The error “Exception parsing query near 'limit”' will occur when the syntax of the query is not proper or it may not be delegated to Virtual DataPort. In Denodo,at this moment Limit is only supported at the end of a SELECT statement to reduce the size of the result set but it cannot be used in subqueries.

Can we use WHERE clause twice in SQL?

But yes, you can use two WHERE.


1 Answers

From the manual:

The number of values in the IN list is only limited by the max_allowed_packet value.

like image 99
D'Arcy Rittich Avatar answered Sep 16 '22 19:09

D'Arcy Rittich