开发者学堂课程【MySQL数据库入门学习:where 语句中in操作符使用】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/451/detail/5580
where 语句中in 操作符使用
in语法:
select* form 表名 where 列名in (value1,value2...)
select* form 表名 where 列名in(select 列名form表名)
//从某个表查出的数据集
注解:
列名in(value1,value2...)等同于列名=value1 or=value2...
演示:
mysql>select *from book;
id title content pages
1 sun nice day 10
2 title nice day 9
3 nice tree bad day 20
5 color nice day 3
4 redcolorday nice day 15
mysql>select *from book2;
id title content pages
1 sun nice day 10
2 title nice day 9
3 nice tree bad day 20
5 color nice day 3
4 redcolorday nice day 15
NULL NULL NULL 0
NULL c NULL 0
NULL c NULL 0
NULL c NULL 0
筛选book表中title的值为sun或者color的数据
mysql>select *from book where title in(‘sun’,’color’);
id title content pages
1 sun nice day 10
5 color nice day 3
筛选id<4的title数据
mysql>select *from book where title in(select title from book2 where id<4)
id title content pages
1 sun nice day 10
2 title nice day 9