赞
踩
not exists常用于子查询跟主查询之间,用于条件判断,根据一个条件返回一个布尔值,从而确定下一步操作如何进行,not exists是exists或in的对立面
story table
story_id | story_name | create_user_id | update_user_id |
---|---|---|---|
1 | 1111 | 1 | 2 |
2 | 2222 | 1 | 3 |
3 | 3333 | 4 | 10 |
4 | 4444 | 5 | 10 |
user table
user_id | user_name |
---|---|
1 | AAA |
2 | BBB |
3 | CCC |
4 | DDD |
select *
from story A
where not exists(
select 1 from user B where A.create = B.id
)
结果
story_id | story_name | create_user_id | update_user_id |
---|---|---|---|
4 | 4444 | 5 | 10 |
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。