WEB开发网
开发学院数据库MSSQL Server 在SQL中删除重复记录(多种方法) 阅读

在SQL中删除重复记录(多种方法)

 2008-10-07 10:08:35 来源:WEB开发网   
核心提示: 1 sunshine10000 1 sunshine10000 2 semon20000 2 semon 20000 3 xyz 30000 2 semon 20000SQL> select distinct * from employee; EMP_ID EMP_NAME

1 sunshine                   10000     

1 sunshine                   10000     

2 semon                    20000     

2 semon                     20000     

3 xyz                      30000     

2 semon                     20000

SQL> select distinct * from employee;   

EMP_ID EMP_NAME  SALARY

---------- ---------------------------------------- ----------     

1 sunshine                   10000     

2 semon                     20000     

3 xyz                       30000

SQL> select * from employee group by emp_id,emp_name,salary having count (*)>1   

EMP_ID EMP_NAME  SALARY

---------- ---------------------------------------- ----------     

1 sunshine                   10000     

2 semon                     20000

SQL> select * from employee e1 where rowid in (select max(rowid) from employe e2

where e1.emp_id=e2.emp_id and  e1.emp_name=e2.emp_name and e1.salary=e2.salary);   

EMP_ID EMP_NAME     SALARY

---------- ---------------------------------------- ----------     

上一页  1 2 3 4 5  下一页

Tags:SQL 删除 重复

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接