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

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 100
    Comment on it

    In MySQL, the WHERE clause is used to filter records from a table. The WHERE clause is used to get the records that match the specified criteria in that.

    WHERE Clause Syntax

    SELECT column_name,column_name
    FROM table_name
    WHERE column_name operator value;
    

    We have a table "employee" as below:

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

    WHERE Clause Example

    The below statement selects all the employees from the country "Canada" from the "employee" table:

    SELECT * FROM emplyee
    WHERE country="Canada";
    

    Result:

        id  first_name            last_name       country
        .......................................................
        1   John                     Simp         Canada
        2   Chris                    Hely         Canada
        4   Jenny                    Mill         Canada
    

    We can also use other operators with WHERE clause apart from = operator.

    Operators in The WHERE Clause

    The below operators can be used in the WHERE clause:

    Operator   Description
    =          Equal
    <>         Not equal. It can be !=
    >          Greater than
    <          Less than
    >=         Greater than or equal
    <=         Less than or equal
    BETWEEN    Between in a range
    LIKE       Search for a pattern
    IN         To specify multiple possible values for a column (for this we pass array of values)
    

    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: