Results 1 to 2 of 2

Thread: Distinct keyword in Oracle SQL

  1. #1
    Junior Member
    Join Date
    Oct 2006
    Answers
    5

    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


  2. #2
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact