distinct去掉重复记录

SQL> select deptno from emp;

    DEPTNO                                                                                                                                            
----------                                                                                                                                            
        20                                                                                                                                            
        30                                                                                                                                            
        30                                                                                                                                            
        20                                                                                                                                            
        30                                                                                                                                            
        30                                                                                                                                            
        10                                                                                                                                            
        20                                                                                                                                            
        10                                                                                                                                            
        30                                                                                                                                            
        20                                                                                                                                            

    DEPTNO                                                                                                                                            
----------                                                                                                                                            
        30                                                                                                                                            
        20                                                                                                                                            
        10                                                                                                                                            

已选择 14 行。

SQL> select distinct deptno from emp;

    DEPTNO                                                                                                                                            
----------                                                                                                                                            
        30                                                                                                                                            
        20                                                                                                                                            
        10                                                                                                                                            

SQL> select job from emp;

JOB                                                                                                                                                   
---------                                                                                                                                             
CLERK                                                                                                                                                 
SALESMAN                                                                                                                                              
SALESMAN                                                                                                                                              
MANAGER                                                                                                                                               
SALESMAN                                                                                                                                              
MANAGER                                                                                                                                               
MANAGER                                                                                                                                               
ANALYST                                                                                                                                               
PRESIDENT                                                                                                                                             
SALESMAN                                                                                                                                              
CLERK                                                                                                                                                 

JOB                                                                                                                                                   
---------                                                                                                                                             
CLERK                                                                                                                                                 
ANALYST                                                                                                                                               
CLERK                                                                                                                                                 

已选择 14 行。

SQL> select distinct job from emp;

JOB                                                                                                                                                   
---------                                                                                                                                             
CLERK                                                                                                                                                 
SALESMAN                                                                                                                                              
PRESIDENT                                                                                                                                             
MANAGER                                                                                                                                               
ANALYST                                                                                                                                               

SQL> select distinct deptno, job from emp;

    DEPTNO JOB                                                                                                                                        
---------- ---------                                                                                                                                  
        20 CLERK                                                                                                                                      
        30 SALESMAN                                                                                                                                   
        20 MANAGER                                                                                                                                    
        30 CLERK                                                                                                                                      
        10 PRESIDENT                                                                                                                                  
        30 MANAGER                                                                                                                                    
        10 CLERK                                                                                                                                      
        10 MANAGER                                                                                                                                    
        20 ANALYST                                                                                                                                    

已选择 9 行。

SQL> --distinct作用于后面所有的列

distinct作用于后面所有的列,从以上的代码可以看出

纸上学来终觉浅,觉知此事需躬行
原文地址:https://www.cnblogs.com/dreamHighMjc/p/7339527.html