zoukankan      html  css  js  c++  java
  • Mysql中WHERE IN,UNION 用法详解

    WHERE IN 用法

    这里分两种情况来介绍

    1、in 后面是记录集,如:

    select  *  from  table  where   uname  in(select  uname  from  user); 

     

    2、in 后面是字符串,如:

    select  *  from  table  where   uname  in('aaa',bbb','ccc','ddd','eee',ffff''); 

    注意:这里一定要将字符串用单引号'' 标注起来;

     

    3、in 后面是数组,用如下方法,请参考:

    //$pieces是含数据的数组

    for($i=0;$i<count($pieces);$i++){

    $uname=$uname."'".$pieces[$i]."',";

    }

    $the_uname ="uname in(".$uname."'')";

    select  *  from  table  where    ".$the_uname." ;

    备注:这种方法的原理其实很简单,二就是把数组编程上面“第2种情况”的形式

    UNION 用法

    (selectfrom tbl_name where A=10 and B=1)

    UNION

    (selectfrom tbl_name where A=11 and B=2)order by a limit 10;

     

     

  • 相关阅读:
    python学习-3 字典
    python学习-3
    python学习-3
    python学习日记-2
    python学习日记
    FTP文件传输
    unity实现截屏功能
    使用C++来写数据库
    background使用
    一张图说明DIV盒子距离
  • 原文地址:https://www.cnblogs.com/stsinghua/p/6419373.html
Copyright © 2011-2022 走看看