Geeks Talk

Prepare for your Next Interview




Distinct keyword in Oracle SQL

This is a discussion on Distinct keyword in Oracle SQL within the SQL forums, part of the Databases category; Hi, I have one doubts in using the Distinct keyword to suppress the duplicates from the performance point of view. Why we should not use the Distinct Keyword in the ...


Go Back   Geeks Talk > Databases > SQL

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 03-28-2008
Junior Member
 
Join Date: Oct 2006
Location: chennai
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
ily_saravanan is on a distinguished road
Distinct keyword in Oracle SQL

Hi,

I have one doubts in using the Distinct keyword to suppress the duplicates from the performance point of view. Why we should not use the Distinct Keyword in the Select statement. To suppress the duplicate, which one is the best to use to avoid the duplication.

while using the Distinct keyword in select clause, I am getting an Performance problem.

If any body knows, please let me know.

Thanks in advance.


Thanks,
Saravanan.P
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-29-2008
Expert Member
 
Join Date: Sep 2007
Posts: 754
Thanks: 22
Thanked 64 Times in 63 Posts
krishnaindia2007 is on a distinguished road
Re: Distinct keyword in Oracle SQL

Quote:
Originally Posted by ily_saravanan View Post
Hi,

I have one doubts in using the Distinct keyword to suppress the duplicates from the performance point of view. Why we should not use the Distinct Keyword in the Select statement. To suppress the duplicate, which one is the best to use to avoid the duplication.

while using the Distinct keyword in select clause, I am getting an Performance problem.

If any body knows, please let me know.

Thanks in advance.


Thanks,
Saravanan.P
To eliminate duplicate records you may use group by instead of using distinct as follows

SQL> SELECT DISTINCT DEPTNO,JOB FROM EMP;

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

9 rows selected.

SQL> SQL> SELECT DEPTNO, JOB, COUNT(*) FROM EMP
2 GROUP BY DEPTNO,JOB;

DEPTNO JOB COUNT(*)
--------- --------- ---------
10 CLERK 1
10 MANAGER 1
10 PRESIDENT 1
20 CLERK 2
20 ANALYST 2
20 MANAGER 1
30 CLERK 1
30 MANAGER 1
30 SALESMAN 4

9 rows selected.
Reply With Quote
Reply

  Geeks Talk > Databases > SQL


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
Load Distinct and Duplicate values to different targets tanya123 Data Warehousing 1 02-25-2008 09:06 PM
ASM keyword in C language Geek_Guest C and C++ 1 08-21-2007 02:01 AM
Alternative for SELECT DISTINCT to query 2 million records Geek_Guest SQL 1 08-06-2007 09:29 AM
difference bet unique and distinct smitai Oracle Certification 2 06-18-2007 04:00 AM
"like" keyword in oracle.. psuresh1982 Oracle 5 12-22-2006 10:19 AM


All times are GMT -4. The time now is 12:16 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved