MySQL中是否有一个运算符来实现多个NOT条件,例如WHERE id!= 5 AND id!= 10 AND id!= 15?
是的,因为此MySQL带有NOTIN。
语法如下
SELECT *FROM yourTableName WHERE yourColumnName NOT IN(1,2,7);
为了理解上述语法,让我们创建一个表。创建表的查询如下
mysql> create table User_informations - > ( - > UserId int, - > UserName varchar(20) - > );
使用insert命令在表中插入一些记录。
查询如下
mysql> insert into User_informations values(12,'Maxwell'); mysql> insert into User_informations values(7,'David'); mysql> insert into User_informations values(1,'Ramit'); mysql> insert into User_informations values(10,'Bob'); mysql> insert into User_informations values(2,'Carol'); mysql> insert into User_informations values(14,'Sam'); mysql> insert into User_informations values(6,'Mike'); mysql> insert into User_informations values(4,'Robert');
使用select语句显示表中的所有记录。
查询如下
mysql> select *from User_informations;
以下是输出
+--------+----------+ | UserId | UserName | +--------+----------+ | 12 | Maxwell | | 7 | David | | 1 | Ramit | | 10 | Bob | | 2 | Carol | | 14 | Sam | | 6 | Mike | | 4 | Robert | +--------+----------+ 8 rows in set (0.00 sec)
以下是您使用NOT提出的要求的实现IN()。
查询如下
mysql> select *from User_informations where UserId NOT IN(1,2,7);
以下是输出
+--------+----------+ | UserId | UserName | +--------+----------+ | 12 | Maxwell | | 10 | Bob | | 14 | Sam | | 6 | Mike | | 4 | Robert | +--------+----------+ 5 rows in set (0.00 sec)
热门推荐
10 毛笔哥哥结婚祝福语简短
11 向国庆送祝福语简短
12 建队节祝福语简短
13 朋友喜得外孙简短祝福语
14 小店营业的祝福语简短
15 餐饮生日祝福语简短独特
16 鲜花英语祝福语卡片简短
17 男朋友暴富祝福语简短
18 婶婶拜年祝福语大全简短