mysql in的用法

  • Post author:
  • Post category:mysql




MySQL in 的用法

in常用于where表达式中,其作用是查询某个范围内的数据,而not in与in作用相反


1. in 基本用法

select name,sex,age,grade from student where age in (11,12,13);


2. in 多个字段同时使用

select name,sex,age,grade  from student where (age,grade) in ((7,1),(9,2),(11,3));


3. in 多表同时多个字段使用

select * from user where (user_id,type) not in (select a.user,a.type from user as a , user_relation as b  where a.user_id=b.user_id and a.type=b.user_type) limit 0,10;


4. not in 基本用法

select a.st_id,a.name,a.sex from student a where a.st_id not in (select b.st_id from score b where score < 60);



版权声明:本文为weixin_43421142原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。