使用union来取代where in:我相对的测试了一下为什么用union反而比where in要慢啊,但是网上建议用union。

解决方案 »

  1.   

    历史如何使用union的呢,把原句贴出来。
      

  2.   

    SELECT * FROM bc_article where id = 287 union  SELECT * FROM bc_article where id = 289 union 
    SELECT * FROM bc_article where id = 290 union  
    SELECT * FROM bc_article where id = 291 union  
    SELECT * FROM bc_article where id = 292 union  
    SELECT * FROM bc_article where id = 293 union  
    SELECT * FROM bc_article where id = 294 union   SELECT * FROM bc_article where id = 295
      

  3.   

    另外像这种问题一般来说有一个临界点的,也就是说在某些数据量下union比 where in高但是超过这些数据量后就不一样了,要根据具体情况来的,另外索引也有很大的影响
      

  4.   

    什么文章说 union 比 where in 好?贴上来咱也学习学习。
    ————————————————————————————————
    基于CSDN论坛提供的插件扩展功能,自己做了个签名档工具,分享给大家,欢迎技术交流 :)
      

  5.   

    是不是当你数据量大的时候用union查询会比where in快啊
      

  6.   

    http://dingchaoqun12.blog.163.com/blog/static/116062504201072753744403/
      

  7.   

    是不是当你数据量大的时候用union查询会比where in快啊