sql查询显示一个字段上没有重复记录的所有字段 [英] sql query to display all the fields with no duplicate records on one field

查看:180
本文介绍了sql查询显示一个字段上没有重复记录的所有字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要加入两个表,即学校和调查,并在第二个表格中显示没有重复字段[SchoolID]的记录。直到我查询为



 选择 * 来自 
选择 * 来自 [学校] < span class =code-keyword>其中 [BoroughID] = 19 [CurrentAccreditationTypeID] = 2)st
加入
选择 * 来自选择 不同 [SchoolID] 来自 [Survey] 其中 [SurveyDate]> = ' 2014-01-09 00 :00:00:000' [SurveyDate]< = ' 2015-31-08 00:00:00:000' as [ID],[SurveyID])s
st。[SchoolID] = s。[SchoolID]





但是没有用。我操纵了查询



 选择 * 来自 
选择 * 来自 [学校] < span class =code-keyword>其中 [BoroughID] = 19 [CurrentAccreditationTypeID] = 2)st
join
select distinct [SchoolID] 来自 [Survey] 其中 [SurveyDate]> = ' 2014-01-09 00:00:00:000' [SurveyDate]< = ' 2015-31-08 00:00:00:000')s
st。[SchoolID] = s。[SchoolID]





然后另一个表中的字段调查表没有显示。



任何人都可以帮我查询显示表格的所有字段,而不显示表格[SchoolID]表中的重复项[Survey单独。

解决方案

SELECT EMP2.EMPLOYID,emp1.FRSTNAME FROM EMP2

INNER JOIN emp1

ON EMP2.EMPLOYID = emp1.EMPLOYID





只在结果中选择你想要的列名,希望这个例子可以帮到你。

I need to join two tables namely Schools and Survey and display the records without duplicate of the field [SchoolID] in the second. till I have queried as

select * from
(Select * from [School] where [BoroughID]=19 and [CurrentAccreditationTypeID]=2)st
 join 
(select * from(select distinct [SchoolID] from [Survey] where [SurveyDate]>='2014-01-09 00:00:00:000' and [SurveyDate]<='2015-31-08 00:00:00:000')as [ID], [SurveyID]) s
on st.[SchoolID]= s.[SchoolID]



But is not working. I manipulated the query as

select * from
(Select * from [School] where [BoroughID]=19 and [CurrentAccreditationTypeID]=2)st
 join 
(select distinct [SchoolID] from [Survey] where [SurveyDate]>='2014-01-09 00:00:00:000' and [SurveyDate]<='2015-31-08 00:00:00:000') s
on st.[SchoolID]= s.[SchoolID]



Then the other fields in table 'Survey table are not displaying.

Can anyone help me query to display all the fields of both the table without the duplicate on the field [SchoolID] of the table [Survey] alone.

解决方案

SELECT EMP2.EMPLOYID,emp1.FRSTNAME FROM EMP2
INNER JOIN emp1
ON EMP2.EMPLOYID=emp1.EMPLOYID


select those column name only which you want in your result,hope this example can help you.


这篇关于sql查询显示一个字段上没有重复记录的所有字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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