How many values in an “in” clause is too many in a SQL query?

前端 未结 4 1376
挽巷
挽巷 2021-02-12 19:14

I have a SQL query that uses the values of an array in its WHERE clause:

 $ids = array 
         ( 
           [0] => 1 
           [1] => 2 
           [2         


        
4条回答
  •  忘了有多久
    2021-02-12 19:40

    Oracle has a limit of 1000, which I've hit before. MySQL doesn't seem to mind. The best solution is not to use an IN clause for that large a dataset though. Where do the ids come from? If from the same DB, then see if you can use a subquery instead that searches based on one parameter e.g. userid to find the linked ids. This will be far more efficient as MySQL can do a join internally using indexes.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题