郑州王师傅哪个是真的:sql查询问题(查找fid是否有下级目录),请大家帮帮

来源:百度文库 编辑:杭州交通信息网 时间:2024/06/29 23:41:28
我现在有个表,结构如下:fid varchar2(文件id), pid varchar2(文件上级目录id)
其中数据为:fid pid
0 null
1 0
2 1
3 2
想查找fid是否有下级目录应该如何写select语句

select * from t1 a where exists(select fid from t1 where pid=a.dif)

有记录就有下级目录,无记录则没有

是找fid有没有上级目录吧?
select fid
from table
where pid is not null