在MySQL中使用<>即不等于来从表中排除特定行。让我们首先创建一个表-
create table DemoTable -> ( -> Id int, -> FirstName varchar(100) -> );
使用插入命令在表中插入一些记录-
insert into DemoTable values(1,'John'); insert into DemoTable values(2,'Chris'); insert into DemoTable values(3,'Robert'); insert into DemoTable values(4,'David');
使用select语句显示表中的所有记录-
select *from DemoTable;
输出结果
这将产生以下输出-
+------+-----------+ | Id | FirstName | +------+-----------+ | 1 | John | | 2 | Chris | | 3 | Robert | | 4 | David | +------+-----------+ 4 rows in set (0.00 sec)
这是从表中排除特定行的查询-
select Id,FirstName from DemoTable where Id <> 2;
这将产生以下输出-
+------+-----------+ | Id | FirstName | +------+-----------+ | 1 | John | | 3 | Robert | | 4 | David | +------+-----------+ 3 rows in set (0.00 sec)