Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is it considered too much for using strings in a MySQL IN clause?

Please tell me from experience with using the "IN clause" in a MySQL query is considered to be too large of a list to push through to be considered good practice?

Example scenario is I have a string of user ID numbers that I will pull from a cache, it can range from anywhere from 1 number all the way up to being 5,000 numbers in this list and I will use a mysql query with this list like this example;

SELECT column FROM table 
WHERE userid 
IN ( 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 )

Can you give me your thoughts on this issue please?

like image 738
JasonDavis Avatar asked Jul 29 '09 07:07

JasonDavis


People also ask

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

The number of values in the IN Caluse can vary anywhere from 0 to thousands.

How many arguments will accept by a limit clause in MySQL?

In MySQL the LIMIT clause is used with the SELECT statement to restrict the number of rows in the result set. The Limit Clause accepts one or two arguments which are offset and count. The value of both the parameters can be zero or positive integers.

What does in clause do in MySQL?

The MySQL IN Operator The IN operator allows you to specify multiple values in a WHERE clause. The IN operator is a shorthand for multiple OR conditions.

How do I find the length of a string in MySQL?

MySQL LENGTH() Function The LENGTH() function returns the length of a string (in bytes).


1 Answers

It should be noted that some databases have limits on the number of entries within an IN clause - Oracle versions <= 10 are limited to 1000. I'm not sure about v11.

like image 145
Clay Mitchell Avatar answered Nov 14 '22 23:11

Clay Mitchell