SQL inner join去重复 SELECT distinct * from table查询后面加上distinct 去除重复数据 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 已经有distinct了 语句的第一行就有distinct select distinct [tEmployee].[EmpName]as'User',[tEmployee].[EmpPassword], [tDepartment].[DeptId],[tDepartment].[DeptName],[tDepartment].[DeptNO],[tCompanyEmployee].[EmpName],[tCompanyEmployee].[EmpNO],[tCompanyEmployee].[Sex]from [tEmployee]inner join [tDepartment] on [tEmployee].[DeptID]=[tDepartment].[DeptID] inner join [tCompanyEmployee] on [tEmployee].[DeptID]=[tCompanyEmployee].[DeptID] select distinct * from(select [tEmployee].[EmpName]as'User',[tEmployee].[EmpPassword], [tDepartment].[DeptId],[tDepartment].[DeptName],[tDepartment].[DeptNO],[tCompanyEmployee].[EmpName],[tCompanyEmployee].[EmpNO],[tCompanyEmployee].[Sex]from [tEmployee]inner join [tDepartment] on [tEmployee].[DeptID]=[tDepartment].[DeptID] inner join [tCompanyEmployee] on [tEmployee].[DeptID]=[tCompanyEmployee].[DeptID]) ok搞定条件不够 所以无法去掉重复 tDepartment字段:[DeptID] [DeptNO] [DeptName]tCompanyEmployee字段:[cEmpID] [DeptID] [EmpNO] [EmpName] [Sex]tEmployee字段:[EmpID] [cEmpID] [DeptID] [EmpName] [EmpPassword]第二个表和第三个表里面有多个字段相同就在inner join 'table' on后面再加一个条件语句:create view v_tDep_tComas select [tDepartment].[DeptId],[tDepartment].[DeptName],[tDepartment].[DeptNO], [tCompanyEmployee].[cEmpID],[tCompanyEmployee].[EmpName],[tCompanyEmployee].[EmpNO],[tCompanyEmployee].[Sex] from [tDepartment] inner join [tCompanyEmployee] on [tDepartment].[DeptID]=[tCompanyEmployee].[DeptID] GOselect * from [v_tDep_tCom]inner join [tEmployee]on [v_tDep_tCom].[DeptID]=[tEmployee].[DeptId] and [v_tDep_tCom].[cEmpID]=[tEmployee].[cEmpID] 看起来还真有点费劲。这几天我也遇到了inner join后出现重复数据的问题。 iis打不开html文件,其它的文件能打开 有个NetVideoActiveX23.ocx控件,已注册,如和添加到工具箱 页面Session和变量内容全部丢失 GridView模板列获取行号 一个电子商务的问题 打包的asp.net程序,安装在win2003上后,在iis里面启动不了,如何解决,谢谢!在线等! 菜鸟求助!关于 ASP。NET的树型控件 在线等~~~~~~~~~~~~~ datagird问题,请高手指教!!! 求救,事务问题!!! asp.net修改设置会话超时间不生效,是什么原因? 两个int相除怎么得到double类型 绑定控件我懂,不知绑定页是什么意思
select distinct
[tEmployee].[EmpName]as'User',[tEmployee].[EmpPassword],
[tDepartment].[DeptId],[tDepartment].[DeptName],[tDepartment].[DeptNO],
[tCompanyEmployee].[EmpName],[tCompanyEmployee].[EmpNO],[tCompanyEmployee].[Sex]
from [tEmployee]
inner join [tDepartment] on [tEmployee].[DeptID]=[tDepartment].[DeptID] inner join [tCompanyEmployee] on [tEmployee].[DeptID]=[tCompanyEmployee].[DeptID]
[tEmployee].[EmpName]as'User',[tEmployee].[EmpPassword],
[tDepartment].[DeptId],[tDepartment].[DeptName],[tDepartment].[DeptNO],
[tCompanyEmployee].[EmpName],[tCompanyEmployee].[EmpNO],[tCompanyEmployee].[Sex]
from [tEmployee]
inner join [tDepartment] on [tEmployee].[DeptID]=[tDepartment].[DeptID] inner join [tCompanyEmployee] on [tEmployee].[DeptID]=[tCompanyEmployee].[DeptID]
)
条件不够 所以无法去掉重复
tDepartment字段:
[DeptID] [DeptNO] [DeptName]
tCompanyEmployee字段:
[cEmpID] [DeptID] [EmpNO] [EmpName] [Sex]
tEmployee字段:
[EmpID] [cEmpID] [DeptID] [EmpName] [EmpPassword]
第二个表和第三个表里面有多个字段相同
就在inner join 'table' on后面再加一个条件
语句:
create view v_tDep_tCom
as
select
[tDepartment].[DeptId],[tDepartment].[DeptName],[tDepartment].[DeptNO],
[tCompanyEmployee].[cEmpID],[tCompanyEmployee].[EmpName],[tCompanyEmployee].[EmpNO],[tCompanyEmployee].[Sex]
from [tDepartment]
inner join [tCompanyEmployee]
on [tDepartment].[DeptID]=[tCompanyEmployee].[DeptID]
GOselect *
from [v_tDep_tCom]
inner join [tEmployee]
on [v_tDep_tCom].[DeptID]=[tEmployee].[DeptId] and [v_tDep_tCom].[cEmpID]=[tEmployee].[cEmpID]