Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • What is the use of DISTINCT statement in MySQL.

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 411
    Comment on it

    In MySQL, the SELECT DISTINCT statement is used to return only distinct values means if in a table, a column has duplicate values then SELECT DISTINCT statement will be used to get different values.

    SELECT DISTINCT Syntax

    SELECT DISTINCT column_name,column_name
    FROM table_name;
    

    We have a table "employee" as below:

        employee
    
        id  first_name            last_name       country
        .......................................................
        1   John                     Simp         Canada
        2   Chris                    Hely         Canada
        3   John                     Roy          Korea
        4   Jenny                    Mill         Korea
        5   Jenny                    Simpson      London
    

    SELECT DISTINCT Example

    The below statement selects only the distinct values from the "country" columns of the "employee" table:

    SELECT DISTINCT country FROM employee;
    

    Result:

        Country 
        ...........
        Canada
        Korea
        London
    

    Hope this will help you :)

 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: