MySQL IN子句:最大参数个数 [英] MySQL IN clause: max number of arguments

查看:5616
本文介绍了MySQL IN子句:最大参数个数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您有以下查询:

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_pa​​cket"值的约束.

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_pa​​cket

这篇关于MySQL IN子句:最大参数个数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆