MySQL IN子句:最大参数个数 [英] MySQL IN clause: max number of arguments
问题描述
假设您有以下查询:
SELECT * FROM table1 WHERE table1.id IN (1, 2, 3, 4, 5, ..., 999999)
IN
子句中的项目数的合理最大值是多少?我正在使用Sphinx生成全文搜索结果,并将ID插入MySQL查询.这是可以接受的方式吗?
What is a reasonable maximum for the number of items in the IN
clause? I'm using Sphinx to generate full-text search results and inserting the IDs into a MySQL query. Is this an acceptable way to do it?
推荐答案
您还可以让IN子句获取查询结果,例如:
You can also have the IN clause take the results of a query, such as:
SELECT * FROM table1
WHERE table1.id IN
(
SELECT id from table2
)
这样,您无需生成带有所有可能值的文本字符串.
That way, you don't need to generate a text string with all the possible values.
在mysql中,您应该能够根据需要在IN子句中放置尽可能多的值,仅受"max_allowed_packet"值的约束.
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".
http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_in http://dev.mysql.com/doc /refman/5.0/en/server-system-variables.html#sysvar_max_allowed_packet
这篇关于MySQL IN子句:最大参数个数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!