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 送给学长毕业祝福语简短