想要加入两个表,但我的查询不起作用,任何人都可以帮助,来自两个表的Iwant数据 [英] want to join two tables but my query is not working can anyone help,Iwant data from both tables

查看:65
本文介绍了想要加入两个表,但我的查询不起作用,任何人都可以帮助,来自两个表的Iwant数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个表我还想要来自表2的数据。即大学必须通过使用申请表编号和表2中的
字段来匹配表1(ApplicationForm)(ApplicationFormSuppliment_phy)是applicationno,userID,university,other university,prnno





there are two tables I also want data from table no 2. i.e university which must match to table no 1(ApplicationForm ) by using application form number and
fields in table no 2(ApplicationFormSuppliment_phy) are applicationno,userID,university,other university,prnno


SELECT [ApplicationNumber],[Surname]
      ,[Firstname]
      ,[Middlename],[Gender],[State],[UniversityBoard]
FROM dbo.ApplicationForm 
AS a
    INNER JOIN dbo.ApplicationFormSuppliment_phy AS p
    ON a.Userid = p.UserId
    where DeptId='17' and SubjectId='27' 
ORDER BY p.ApplicationNo 

推荐答案

如果没有更具体的具体指示,很难提供帮助你得到的数据的方式是错误的,所以接下来有点猜测。



你可能会错过应用程序编号的额外连接条件。如果不按应用程序编号限制连接,则可能会获得比预期更多的行。另见CHill60的评论。



您没有说,但我认为[DeptID]和[SubjectID]是[Application]的属性



Difficult to help without a more specific specific indication of the way that the data you get back is wrong so what follows is a bit of a guess.

You may be missing the extra join condition on the application number. If you don't restrict the join by application number than you may get more rows than you expect to get. See also CHill60's comment.

You don't say but I assume that [DeptID] and [SubjectID] are attributes of [Application]

select [A].*, [P].*
from
  [Application] as [A]
inner join [ApplicationFormSupplement_Phy] as [P]
      on  [P].[UserID]        = [A].[UserID]
      and [P].[ApplicationNo] = [A].[ApplicationNumber]
where
      [A].[DeptID]    = '17'
  and [A].[SubjectID] = '27'

order by [A].[ApplicationNumber]


这篇关于想要加入两个表,但我的查询不起作用,任何人都可以帮助,来自两个表的Iwant数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆