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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 307
    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.

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

    ex

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

    query

    SQL> SELECT SALARY FROM CUSTOMERS
         ORDER BY SALARY;
    SQL> SELECT SALARY FROM CUSTOMERS
         ORDER BY SALARY;

    The result

    +----------+
    | SALARY   |
    +----------+
    |  1500.00 |
    |  2000.00 |
    |  2000.00 |
    |  4500.00 |
    |  6500.00 |
    |  8500.00 |
    | 10000.00 |
    +----------+

    the query with distinct keyword

    SQL> SELECT DISTINCT SALARY FROM CUSTOMERS
     ORDER BY SALARY;

    The result

    +----------+
    | SALARY   |
    +----------+
    |  1500.00 |
    |  2000.00 |
    |  4500.00 |
    |  6500.00 |
    |  8500.00 |
    | 10000.00 |
    +----------+

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: