关于查询的问题

osuwali 2009-01-03 03:22:17
表A 有以下字段:
id(本机构标识) uperid(上级机构标识)
其中根机构是没有上级机构的,或者说根机构即使设置了uperid(this_id),表A中也没有id=this_id的相关记录。
对于查找表A中的根机构id,有没有什么好的办法。
...全文
33 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zounf 2009-01-03
  • 打赏
  • 举报
回复
完善一下:
select id
from a
where a.uperid is null
or not exists(select 1 from a b where b.id = a.uperid);
zounf 2009-01-03
  • 打赏
  • 举报
回复
select id from a where not exists(select 1 from a b where b.id = a.uperid);

3,496

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧