Section outline

  • Topics Objective

    1. Explain how to solve problem using Basic Where, AND, OR, NOT, Order By   

    Topics Outcomes

    1. Able to implement condition while solving problem using Basic Where, AND, OR, NOT, Order By   


    The SQL WHERE Clause

    The WHERE clause is used to filter records. The WHERE clause is used to extract only those records that fulfill a specified condition.

    WHERE Syntax

    SELECT column1, column2, ... FROM table_name WHERE condition;

    Example

    SELECT * FROM Customers WHERE Country='Mexico';

    SELECT * FROM Customers WHERE CustomerID=1;


    The SQL AND, OR and NOT Operators

    The WHERE clause can be combined with AND, OR, and NOT operators.

    The AND and OR operators are used to filter records based on more than one condition:

    • The AND operator displays a record if all the conditions separated by AND are TRUE.
    • The OR operator displays a record if any of the conditions separated by OR is TRUE.
    • The NOT operator displays a record if the condition(s) is NOT TRUE.


    AND Syntax

    SELECT column1, column2, ... FROM table_name WHERE condition1 AND condition2 AND condition3 ...;

    OR Syntax

    SELECT column1, column2, ... FROM table_name WHERE condition1 OR condition2 OR condition3 ...;

    NOT Syntax

    SELECT column1, column2, ... FROM table_name WHERE NOT condition;


    The SQL ORDER BY Keyword

    The ORDER BY keyword is used to sort the result-set in ascending or descending order. The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.

    ORDER BY Syntax

    SELECT column1, column2, ... FROM table_name ORDER BY column1, column2, ... ASC|DESC;

    • After completing all tasks upload those tasks in drive and upload only drive link here