您可以使用不等于operator(!=)的方式排除SQL中的特定记录。让我们首先创建一个表-
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(20), ClientCountryName varchar(10) );
使用插入命令在表中插入记录-
mysql> insert into DemoTable(ClientName,ClientCountryName) values('John','US'); mysql> insert into DemoTable(ClientName,ClientCountryName) values('David','AUS'); mysql> insert into DemoTable(ClientName,ClientCountryName) values('Mike','UK');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+----+------------+-------------------+ | Id | ClientName | ClientCountryName | +----+------------+-------------------+ | 1 | John | US | | 2 | David | AUS | | 3 | Mike | UK | +----+------------+-------------------+ 3 rows in set (0.00 sec)
以下是查询以排除MySQL中的特定记录,即我们排除具有ClientName David'或ClientCountryName ='AUS'-的记录
mysql> select *from DemoTable where ClientName!='David' or ClientCountryName!='AUS';
+----+------------+-------------------+ | Id | ClientName | ClientCountryName | +----+------------+-------------------+ | 1 | John | US | | 3 | Mike | UK | +----+------------+-------------------+ 2 rows in set (0.00 sec)