简体   繁体   English

如何从一张表中选择关系表中不存在的所有记录?

[英]how to select all records from one table that not exist in relation table?

ObjectClass1对象类 1

OBID | Name

0001 | ob01
0002 | ob02

Relation1关系1

RELID|LEFTOBID|RIGHTOBID|CLASS1|CLASS2

R001 |0001    |000X     |ObjectClass1|ObjectClass2

Now What I want to find out is how to write a query to find out that relation does not exists for OBID 0002现在我想知道的是如何编写查询以找出 OBID 0002 不存在关系

Use not exists as :使用not exists为:

select *
  from ObjectClass1 o
 where not exists
   ( select 1 from Relation1 r where r.LEFTOBID = o.OBID );

Rextester Demo雷克斯特演示

SQL
SELECT  *
FROM    ObjectClass1    obj
LEFT JOIN
        Relation1       rel
  on    obj.OBID = rel.LEFTOBID
WHERE   rel.LEFTOBID is null

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何 select 一个表中的所有记录在另一个表中不存在于另一个表中的某些条件下? - How to select all records from one table that do not exist in another table for certain condition in another table? 如何从一个表中选择另一张表中不存在的所有记录? - How to select all records from one table that do not exist in another table? 如何从一个表中选择特定年份不存在的所有记录? - How to select all records from one table that do not exist in particular year? Select 一个表中的所有记录和另一个表中的匹配记录或 Null(如果不存在) - Select All Records From One Table And Matching Record From Other Table or Null (if not exist) sql-从一个表中选择另一个表中不存在的记录 - sql - Select records from one table that do not exist in the other 如何显示一个表中不存在于另一表中的记录 - How to show records from one table that do not exist in another table Select 基于条件的一个表中的所有记录,而不是另一个表中的所有记录 - Select all records from one table not in another table based on a condition 如何从一个表中选择与SQL Server中的另一个表完全匹配的所有记录? - How to select all records from one table that exactly match another table in SQL Server? 如果存在 2 条记录,则 SQL 从表中选择 - SQL select from a table if 2 records exist 如何基于另一个表中的HABTM关系从一个表中选择项目? Postgres“ ALL”不起作用, - How to select items from one table based on HABTM relation in another? Postgres “ALL” does not work,
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM