MySQL IN condition limit

MysqlConditional Statements

Mysql Problem Overview


Hey, I have to use IN condition in my MySQL statement with a large set of ids.

Example

SELECT * FROM users WHERE id IN (1,2,3,4...100000)

Is there a limit if items the IN statement can have?

Mysql Solutions


Solution 1 - Mysql

No there isn't, check the manual about the IN function:

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

Solution 2 - Mysql

As far as I know in mysql, there is no limit for items in the IN statement.

In oracle altough, there is a limit of 1000 items in the IN statement.

But more the items in IN, your query performance will slow down unless that column is indexed.

Solution 3 - Mysql

enter image description here

1073741824 This is the limit given in Mysql docs

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionxpepermintView Question on Stackoverflow
Solution 1 - MysqlProgmanView Answer on Stackoverflow
Solution 2 - MysqlSachin ShanbhagView Answer on Stackoverflow
Solution 3 - MysqlpraveenView Answer on Stackoverflow