ObjectClass1
OBID | Name
0001 | ob01
0002 | ob02
Relation1
RELID|LEFTOBID|RIGHTOBID|CLASS1|CLASS2
R001 |0001 |000X |ObjectClass1|ObjectClass2
现在我要查找的是如何编写查询以发现OBID 0002不存在该关系
答案 0 :(得分:1)
将not exists
用作:
select *
from ObjectClass1 o
where not exists
( select 1 from Relation1 r where r.LEFTOBID = o.OBID );
答案 1 :(得分:0)
SQL
SELECT *
FROM ObjectClass1 obj
LEFT JOIN
Relation1 rel
on obj.OBID = rel.LEFTOBID
WHERE rel.LEFTOBID is null