Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 在SQL Server中不存在使用_Sql Server_Not Exists - Fatal编程技术网

Sql server 在SQL Server中不存在使用

Sql server 在SQL Server中不存在使用,sql-server,not-exists,Sql Server,Not Exists,我有两张桌子 Doctype ----------- doctypeid doctype DocumentList ----------------- doclistid (pk), projectid, doctypeid, docfile(binary) 我想从doctypeid表中获取所有projectid和doctypeid,其中doctypeid列表(来自Doctype表)不存在于documentlist表中。如果我理解你的问题,你可能会想使用这样的东西: SELECT

我有两张桌子

Doctype
-----------
doctypeid 
doctype 

DocumentList
-----------------
doclistid (pk), 
projectid, 
doctypeid, 
docfile(binary)

我想从
doctypeid
表中获取所有
projectid
doctypeid
,其中
doctypeid
列表(来自
Doctype
表)不存在于
documentlist
表中。

如果我理解你的问题,你可能会想使用这样的东西:

SELECT projectid, doctypeid
FROM DocumentList 
WHERE doctypeid NOT in(1,2,3,4...n)

如果希望
DocumentList
中的
projectid
doctypeid
列表显示其doctypeid在
Doctype
中不存在,请使用以下方法:

SELECT 
    projectid, 
    doctypeid
FROM 
    DocumentList
WHERE 
    NOT EXISTS(SELECT 1 
               FROM Doctype 
               WHERE Doctype.doctypeid = DocumentList.doctypeid)

您是否声明希望所有doctypeid都来自一个doctypeid不在表中的表?如果您先搜索,有很多示例可以说明如何执行此操作:doctypeid是主列表。DocumentList表包含多个doctypeid为的文档。我想获取文档列表表中不存在的所有doctypeid。因此,我可以提醒用户,这些文档仍然丢失。表名已更正。
SELECT 
    projectid, 
    doctypeid
FROM 
    DocumentList
WHERE 
    NOT EXISTS(SELECT 1 
               FROM Doctype 
               WHERE Doctype.doctypeid = DocumentList.doctypeid)