/    /  MySQL – WHERE – Clause

MySQL – WHERE – Clause

 

MySQL - WHERE – Clause

The WHERE clause in MySQL specifies the exact criteria for data or rows that will be impacted by the SQL statement. WHERE clauses can be used with SQL statements such as INSERT, UPDATE, SELECT, and DELETE in order to filter records and perform a variety of operations on the data.

Syntax:

Using the WHERE clause in a SQL SELECT WHERE statement has the following basic syntax.

SELECT * FROM tableName WHERE condition;
  • “SELECT * FROM tableName” is a standard selection statement.
  • “WHERE” is the keyword that restricts the set of results returned by our select query, and “condition” specifies the filter that will be applied to the returned results. There are various types of filters available, such as ranges, single values, and subqueries.

Example:

In the following example, we would use the following query to retrieve the first and last names of all employees whose salary exceeds 500000 in a table named “employees”:

SELECT first_name, last_name
FROM employees
WHERE salary > 50000;

MySQL - WHERE – Clause

Using logical operators such as AND and OR, you can specify multiple conditions within a WHERE clause. The following query, for example, would retrieve the first name and last name of employees whose salary is greater than 50000 and whose hire date is after January 1, 2010:

SELECT first_name, last_name
FROM employees
WHERE salary > 1000 AND hire_date > '1985-11-21';

MySQL - WHERE – Clause