Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Distinct keyword

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 614
    Comment on it

    It is used for conjunction with the select statement to eliminate the all the duplicate record and fetch only the unique record.

    There are many situation that we found duplicate data on the database and better to get unique ones.

    1. SELECT DISTINCT column1, column2,.....columnN
    2. FROM table_name
    3. WHERE [condition]

    ex

    1. +----+----------+-----+-----------+----------+
    2. | ID | NAME | AGE | ADDRESS | SALARY |
    3. +----+----------+-----+-----------+----------+
    4. | 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
    5. | 2 | Khilan | 25 | Delhi | 1500.00 |
    6. | 3 | kaushik | 23 | Kota | 2000.00 |
    7. | 4 | Chaitali | 25 | Mumbai | 6500.00 |
    8. | 5 | Hardik | 27 | Bhopal | 8500.00 |
    9. | 6 | Komal | 22 | MP | 4500.00 |
    10. | 7 | Muffy | 24 | Indore | 10000.00 |
    11. +----+----------+-----+-----------+----------+

    query

    1. SQL> SELECT SALARY FROM CUSTOMERS
    2. ORDER BY SALARY;
    1. SQL> SELECT SALARY FROM CUSTOMERS
    2. ORDER BY SALARY;

    The result

    1. +----------+
    2. | SALARY |
    3. +----------+
    4. | 1500.00 |
    5. | 2000.00 |
    6. | 2000.00 |
    7. | 4500.00 |
    8. | 6500.00 |
    9. | 8500.00 |
    10. | 10000.00 |
    11. +----------+

    the query with distinct keyword

    1. SQL> SELECT DISTINCT SALARY FROM CUSTOMERS
    2. ORDER BY SALARY;

    The result

    1. +----------+
    2. | SALARY |
    3. +----------+
    4. | 1500.00 |
    5. | 2000.00 |
    6. | 4500.00 |
    7. | 6500.00 |
    8. | 8500.00 |
    9. | 10000.00 |
    10. +----------+

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: