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 儿童毕业祝福语 简短6
14 开工仪式横幅祝福语简短
15 孩子日常祝福语大全简短
16 清晨寄语诗句祝福语简短
17 结婚送亲认亲祝福语简短
18 虎年喝酒拜年祝福语简短