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;

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM