Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.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
C# Sql server 2005中的内部联接问题_C#_Asp.net_Sql Server 2005_Inner Join - Fatal编程技术网

C# Sql server 2005中的内部联接问题

C# Sql server 2005中的内部联接问题,c#,asp.net,sql-server-2005,inner-join,C#,Asp.net,Sql Server 2005,Inner Join,当我执行此查询时,在上一次连接中出现错误,表示无法绑定多部分标识符“ContentToIndividual.SubjectId”。但我在两个表中都有SubjectId。我无法理解问题出在哪里。请帮我解决。您没有在主select语句中连接ContentToIndividual。您需要添加它或不引用它 编辑:只需添加,实际上不需要在主选择中添加SubjectMaster或ContentToIndividual连接,因为您没有从任何一个表中选择任何列-记住子查询与主查询是分开的;您只能使用它来获取文件

当我执行此查询时,在上一次连接中出现错误,表示无法绑定多部分标识符“ContentToIndividual.SubjectId”。但我在两个表中都有SubjectId。我无法理解问题出在哪里。请帮我解决。

您没有在主select语句中连接ContentToIndividual。您需要添加它或不引用它

编辑:只需添加,实际上不需要在主选择中添加
SubjectMaster
ContentToIndividual
连接,因为您没有从任何一个表中选择任何列-记住子查询与主查询是分开的;您只能使用它来获取文件ID列表。也可以优化语句的其余部分

   Select FileUpload.FileName AS FINAME, FileUpload.FilePath,MemberPersonalInformation.FirstName As SharedBy  from FileUpload 
   INNER JOIN 
   ContentManagement ON ContentManagement.FileId=FileUpload.FileId  
   INNER JOIN 
   MemberPersonalInformation ON MemberPersonalInformation.MemberId=ContentManagement.CreatedBy 
   INNER JOIN
    SubjectMaster ON ContentToIndividual.SubjectId=SubjectMaster.SubjectId 
    where 
   FileUpload.FileId in
    (Select FileId from ContentManagement where ContentId in
    (Select ContentId from ContentToIndividual where ShowToMemberId=12) 
    AND ContentManagement.ContentTypeId=1 and ContentManagement.SessionId=4)
编辑2:只是为了好玩,我认为这可能会简化一些事情,因为它摆脱了子查询,所以它应该更快

   Select FileUpload.FileName AS FINAME, FileUpload.FilePath,MemberPersonalInformation.FirstName As SharedBy  from FileUpload 
   INNER JOIN 
   ContentManagement ON ContentManagement.FileId=FileUpload.FileId  
   INNER JOIN 
   MemberPersonalInformation ON MemberPersonalInformation.MemberId=ContentManagement.CreatedBy 
   where 
   FileUpload.FileId in
    (Select FileId from ContentManagement where ContentId in
    (Select ContentId from ContentToIndividual where ShowToMemberId=12) 
    AND ContentManagement.ContentTypeId=1 and ContentManagement.SessionId=4)

您尚未在主select语句中加入ContentToIndividual。您需要添加它或不引用它

编辑:只需添加,实际上不需要在主选择中添加
SubjectMaster
ContentToIndividual
连接,因为您没有从任何一个表中选择任何列-记住子查询与主查询是分开的;您只能使用它来获取文件ID列表。也可以优化语句的其余部分

   Select FileUpload.FileName AS FINAME, FileUpload.FilePath,MemberPersonalInformation.FirstName As SharedBy  from FileUpload 
   INNER JOIN 
   ContentManagement ON ContentManagement.FileId=FileUpload.FileId  
   INNER JOIN 
   MemberPersonalInformation ON MemberPersonalInformation.MemberId=ContentManagement.CreatedBy 
   INNER JOIN
    SubjectMaster ON ContentToIndividual.SubjectId=SubjectMaster.SubjectId 
    where 
   FileUpload.FileId in
    (Select FileId from ContentManagement where ContentId in
    (Select ContentId from ContentToIndividual where ShowToMemberId=12) 
    AND ContentManagement.ContentTypeId=1 and ContentManagement.SessionId=4)
编辑2:只是为了好玩,我认为这可能会简化一些事情,因为它摆脱了子查询,所以它应该更快

   Select FileUpload.FileName AS FINAME, FileUpload.FilePath,MemberPersonalInformation.FirstName As SharedBy  from FileUpload 
   INNER JOIN 
   ContentManagement ON ContentManagement.FileId=FileUpload.FileId  
   INNER JOIN 
   MemberPersonalInformation ON MemberPersonalInformation.MemberId=ContentManagement.CreatedBy 
   where 
   FileUpload.FileId in
    (Select FileId from ContentManagement where ContentId in
    (Select ContentId from ContentToIndividual where ShowToMemberId=12) 
    AND ContentManagement.ContentTypeId=1 and ContentManagement.SessionId=4)

您正在将
SubjectMaster
表加入到先前未引用的
ContentToIndividual
表中

SubjectMaster
Join中引用
contenttoindividual
之前,您需要加入到
contenttoindividual

e、 g


注意:即使您在子查询中查询
ContentToIndividual
,如果它不是主选择查询的一部分,您也不能引用其中的列。

您将
SubjectMaster
表加入到以前未引用的
ContentToIndividual
表中

SubjectMaster
Join中引用
contenttoindividual
之前,您需要加入到
contenttoindividual

e、 g


注意:即使在子查询中查询
ContentToIndividual
,如果它不是主选择查询的一部分,也不能引用其中的列。

如果您使用的是SQL management studio,则始终可以使用查询设计器来解决此类问题。它帮助我解决了时间分配问题消除子查询是否加快了速度?如果您使用的是SQL management studio,您可以随时使用查询设计器来解决此类问题。它帮助我完成了时间分配子查询的消除是否加快了速度?我没有尝试,但看起来不错。我如何找到哪个查询工作得快?有几种方法。如果在MSMS中突出显示两个查询,然后右键单击并选择“显示估计的执行计划”,则它将按批次的百分比为每个查询打分。例如,如果一个是20%,另一个是80%,那么第一个可能快四倍。如果您想要更准确的答案,请选择“包含实际执行计划”,在运行两个查询(通过点击F5)后,这将在结果窗口中显示为一个额外的选项卡。当然,这不一定会给出实际的速度差异。要获得实际执行时间的更冗长的方法,请提出一个新问题,我会给您一个更好的答案。我没有尝试过,但看起来不错。如何找到哪个查询工作得更快?有几种方法。如果在MSMS中突出显示两个查询,然后右键单击并选择“显示估计的执行计划”,则它将按批次的百分比为每个查询打分。例如,如果一个是20%,另一个是80%,那么第一个可能快四倍。如果您想要更准确的答案,请选择“包含实际执行计划”,在运行两个查询(通过点击F5)后,这将在结果窗口中显示为一个额外的选项卡。当然,这不一定会给出实际的速度差异。要获得实际执行时间的更冗长的方法,请提出一个新问题,我会给您一个更好的答案。