mysql中 where in 用法详解
来源:互联网 发布:淘宝改版 编辑:程序博客网 时间:2024/05/23 16:27
这里分两种情况来介绍
1、in 后面是记录集,如:
select * from table where uname in(select uname from user);
例子:
SELECT * FROM article WHERE uid IN(SELECT uid FROM user WHERE status=0)
在这个 SQL 例子里,我们实现了查出所有状态为 0 的用户(可能是被禁止)的所有文章。首先通过一个查询得到所有所有 status=0 的用户:
SELECT uid FROM user WHERE status=0
然后将查询结果作为 IN 的列表项以实现最终的查询结果,注意在子查询中返回的结果必须是一个字段列表项。
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种情况”的形式
出处:http://blog.csdn.net/k8080880/article/details/8482659
0 0
- mysql中 where in 用法详解
- mysql中 where in 用法详解
- mysql中 where in 用法详解
- mysql中 where in 用法详解
- mysql中where in用法
- SQL中where in的用法
- mysql中where字句的特殊用法
- MySQL where in 排序
- WHERE语句中BETWEEN与IN的使用教程-MySQL
- yii2 where in的用法
- mysql中using() having where 的用法区别
- mysql中haveing用法(同where类似)
- mysql中having的用法(和where的区别)
- mysql中having的用法(和where的区别)
- 优化mysql中where or和where in语句的效率
- mysql delete where not in
- mysql怎么使用 where in
- SQL 中用法详解 string where = " where 1=1 ";
- 在线客服openfire设置
- 短信猫二次开发
- Xcode8
- JDBC连接数据库七步走
- python socket简述
- mysql中 where in 用法详解
- RawTest '1' must be wrapped in an explicit <Text> component
- 编译环境变量
- WordCount单词计数
- C语言---交换两个数的内容(谷歌面试题)
- GPS定位、基站定位、wifi定位
- 感知器法则
- BitMap算法
- Android截屏的简单实现