参考下面的代码:
-- 创建测试表 create table test_table ( id int, name varchar(10), age int );
-- 插入数据 insert into test_table values (1, 'Amy', 20); insert into test_table values (2, 'Bob', 25); insert into test_table values (3, 'Charlie', 30);
-- 查询测试表中名字不等于'Mary'的所有行 select * from test_table where not exists ( select 1 from test_table where name = 'Mary' );
-- 查询测试表中名字不等于'Amy'的所有行 select * from test_table where not exists ( select 1 from test_table where name = 'Amy' );
-- 查询测试表中名字不等于'Lucy'的所有行 select * from test_table where not exists ( select 1 from test_table where name = 'Lucy' );
-- 结果都正确,可以正常工作。