Where condition in SQL

The MySQL WHERE statement is used to define a circumstance when the data is collected from a separate list or joined to several tables. If the specified circumstance is met, then only the unique value of the table is returned. To extract the information and retrieve only the correct records, you can use the WHERE statement.

Not only, the WHERE condition used in the Selection statement, but it is also used in the UPDATE assertion, DELETE assertion, etc.

Syntax

Now, we have discussed the syntax of the SELECT statement associated with the WHERE condition. It is shown below-

SELECT column1, column2, ..... columnN  

FROM table_name  

WHERE {condition} 

    Note: The WHERE condition is used not only in the Selection assertion but also in the UPDATE assertion, the Remove assertion, etc.!

    You may use contrast or logical operators, such as >, <, =, LIKE, NOT, etc. To define a state. The below-given example will explicitly state this notation.

    For Example-

    Here, we consider the table of CUSTOMERS with the below-given records.

    CustomerIDCustomerNameAddressAgeSalary
    001Hardy ThompsonMaxico2510000.00
    002Sturt Broad Los Angeles2825000.00
    003Joseph WingetCalifornia3056000.00
    004David AndersonNorway2476000.00
    005AlexaDenmark3523000.00

    Now, we will run the below-given query on SQL to fetch the CustomerID, CustomerName and Salary from the above table CUSTOMERS, where the salary is greater than 25000.

    Select CustomerID, CustomerName, Salary   
    
    from CUSTOMERS  
    
    Where Salary > 25000;

    Output

    After the successful execution of the above SQL query, we got the following output.

    Where condition in SQL

    Here, we have another instance where we would get the CustomerID, CustomerName and Salary from the database table named CUSTOMERS for a specific customer named Joseph Winget.

    Select CustomerID, CustomerName, Salary   
    
    from CUSTOMERS  
    
    Where CustomerName = 'Joseph Winget';  

      Output

      After the successful execution of the above SQL query, we got the above-given outcome.

      Where condition in SQL

      Comments

      Leave a Reply

      Your email address will not be published. Required fields are marked *