| 
  
  	|   [VIEWED 10892
            TIMES]  | 
SAVE! for ease of future access.
 |  | 
  
 
 
 
 
   |  | 
   
    | 
		  		
						
			
			
        
     
        
Tyo Din     
	  
	  
		
			
		 
		Please log in to subscribe to Tyo Din's postings.
		 
        Posted on 03-19-16 12:14 
        PM     
   
        Reply 
        
            
            
          [Subscribe] | 
  
  
 | Login in to Rate this Post:     
0  ?   | 
 
 
 
 
   
|  | 
  
   
    |  
        
        
      
        
        		
  
             
		
             
I need to : select distinct * from my_table;  it's not working. What is alternative to this query? I can't use column_names in place of * because there are hundreds of columns in my table. Thanks IT sajha Experts for ur answer.	
    
          
           
 
 
 
 | 
  |  | 
  
  
  
|  | 
  
 
   |  | 
   
    | 
		  		
						
			
			
        
     
        
sajhamitra     
	  
	  
		
			
		 
		Please log in to subscribe to sajhamitra's postings.
		 
        Posted on 03-19-16 1:32 
        PM     [Snapshot: 37]    
   
        Reply 
        
            
            
          [Subscribe] | 
  
  
 | Login in to Rate this Post:     
0  ?   | 
 
 
 
 
   
|  | 
  
   
    |  
        
        
      
        
        		
  
             
		
             
use dynamic query to get list of columns and concatenate select distinct keyword with it and run that dynamic query	
    
          
           
 
 
 
 | 
  |  | 
  
  
  
 
   |  | 
   
    | 
		  		
						
			
			
        
     
        
Tyo Din     
	  
	  
		
			
		 
		Please log in to subscribe to Tyo Din's postings.
		 
        Posted on 03-19-16 2:34 
        PM     [Snapshot: 42]    
   
        Reply 
        
            
            
          [Subscribe] | 
  
  
 | Login in to Rate this Post:     
0  ?   | 
 
 
 
 
   
|  | 
  
   
    |  
        
        
      
        
        		
  
             
		
             
Thanks sajhamitra. But how to concatenate : i) select column_name from all_tab_columns where upper(table_name)='EMP'; with select distinct * from EMP. I mean ,how  to concatenate select distinct keyword with the dynamic query to list columns?	
    
          
           
 
 
 
 | 
  |  | 
  
  
  
 
   |  | 
   
    | 
		  		
						
			
			
        
     
        
WakkaDikka22     
	  
	  
		
			
		 
		Please log in to subscribe to WakkaDikka22's postings.
		 
        Posted on 03-19-16 5:16 
        PM     [Snapshot: 124]    
   
        Reply 
        
            
            
          [Subscribe] | 
  
  
 | Login in to Rate this Post:     
0  ?   | 
 
 
 
 
   
|  | 
  
   
    |  
        
        
      
        
        		
  
             
		
             
SELECT DISTINCTcolumn_name,column_name FROM table_name; SELECT * From table_name; Please understand (*) will return everything, hence DISTINCT *(everything) is a wrong sql statement. DISTINCT specifically looks for unique result set,,The DISTINCT keyword can be used to return only distinct (different) values	
    
          
           
 
 
 
 | 
  |  | 
  
  
  
 
   |  | 
   
    | 
		  		
						
			
			
        
     
        
Tyo Din     
	  
	  
		
			
		 
		Please log in to subscribe to Tyo Din's postings.
		 
        Posted on 03-19-16 6:14 
        PM     [Snapshot: 155]    
   
        Reply 
        
            
            
          [Subscribe] | 
  
  
 | Login in to Rate this Post:     
0  ?   | 
 
 
 
 
   
|  | 
  
   
    |  
        
        
      
        
        		
  
             
		
             
WakkaDikka Mitra, I do  understand your explanation but i want the unique records in a table having more than 100 columns. I can't list all the column names after distinct keyword.	
    
          
           
 
 
 
 | 
  |  | 
  
  
  
 
   |  | 
   
    | 
		  		
						
			
			
        
     
        
niss     
	  
	  
		
			
		 
		Please log in to subscribe to niss's postings.
		 
        Posted on 03-19-16 10:06 
        PM     [Snapshot: 224]    
   
        Reply 
        
            
            
          [Subscribe] | 
  
  
 | Login in to Rate this Post:     
1  ?  Liked by | 
 
 
 
 
   
|  | 
  
   
    |  
        
        
      
        
        		
  
             
		
             
If your table has a PK all rows should be distinct by definition. If you are trying to just select DISTINCT field but somehow return all other columns what should happen for those columns that have more than one value for a particular field value? so You would need to use GROUP BY and some sort of aggregation on the other columns. select * from table group by column name.	
    
          
           
 
 
 
 | 
  |  | 
  
  
  
 
   |  | 
   
    | 
		  		
						
			
			
        
     
        
kunthaun     
	  
	  
		
			
		 
		Please log in to subscribe to kunthaun's postings.
		 
        Posted on 03-20-16 12:04 
        AM     [Snapshot: 257]    
   
        Reply 
        
            
            
          [Subscribe] | 
  
  
 | Login in to Rate this Post:     
0  ?   | 
 
 
 
 
   
|  | 
  
   
    |  
        
        
      
        
        		
  
             
		
             
try this select distinct a.* from my_table a;	
    
          
           
 
 
 
 | 
  |  | 
  
  
  
 
   |  | 
   
    | 
		  		
						
			
			
        
     
        
Tyo Din     
	  
	  
		
			
		 
		Please log in to subscribe to Tyo Din's postings.
		 
        Posted on 03-20-16 6:06 
        PM     [Snapshot: 366]    
   
        Reply 
        
            
            
          [Subscribe] | 
  
  
 | Login in to Rate this Post:     
0  ?   | 
 
 
 
 
   
|  | 
  
   
    |  
        
        
      
        
        		
  
             
		
             
Thanks Kunthaun; it worked.	
    
          
           
 
 
 
 | 
  |  | 
  
  
  
| 
 |