mysql中 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種情況”的形式。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章