如何删除重复值 [英] how to remove duplicate value

查看:70
本文介绍了如何删除重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用内连接或左外连接删除sql中的重复值...





ex:



选择e.name,e.description,t.mobile,m.address from employee e left outer join dept t on e.id = t.id left outer join mail m on m.id1 = e.id1





ans:



员工部门邮件

******** ...... ***** .... *****



id..id1 .. name || id..descr || id1..address ||



1 .. 1 ... sek | | 1 ... chenn || .1 ... kovil

2 .. 2 .... ram || 2 ... ramm || .2 .... stree





ans coming





sek .. chenn..kovil

sek..rammm..stree

ram..chenn.kovil

ram..rammm.stree


i不要重复值

how to remove duplicate value in sql using inner join or left outer join...


ex:

select e.name,e.description,t.mobile ,m.address from employee e left outer join dept t on e.id=t.id left outer join mail m on m.id1=e.id1


ans:

employee dept mail
********......*****....*****

id..id1.. name||id..descr||id1..address||

1.. 1 ... sek ||1...chenn||.1... kovil
2.. 2 ....ram ||2...ramm ||.2....stree


ans coming


sek..chenn..kovil
sek..rammm..stree
ram..chenn.kovil
ram..rammm.stree

i dont want duplicate value

推荐答案

使用Select-Distinct子句( [ ^ ])。
Use Select-Distinct clause (see[^]).


请检查此代码



Please check this code

DECLARE @Employee TABLE
(
  ID int, 
  ID1 int, 
  Name nvarchar(10)
)
INSERT INTO @Employee VALUES(1,1,'Sek')
INSERT INTO @Employee VALUES(2,2,'Ram')

DECLARE @Dept TABLE
(
  ID int, 
  [Description] nvarchar(10),
  Mobile int
)
INSERT INTO @Dept VALUES(1,'Chenn',1234567891)
INSERT INTO @Dept VALUES(2,'Ramm',1234567891)

DECLARE @Mail TABLE
(
  ID1 int, 
  [Address] nvarchar(10)
)
INSERT INTO @Mail VALUES(1,'kovil')
INSERT INTO @Mail VALUES(2,'stree')


Select e.Name,t.description,t.mobile ,m.address 
FROM @employee e 
	LEFT OUTER JOIN @Dept t on e.id=t.id 
	LEFT OUTER JOIN @Mail m on m.id1=e.id1


这篇关于如何删除重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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