MySQL Where Clause is a statement used for filtering records based on conditions.
The basic syntax of a where Clause is
Select <column-names> from <table>
where <conditions>;
We will look at examples using different options.
We will use the where Clause with literal values to get zero or more records.
select * from departments where dept_id =2;
SELECT * FROM DEPARTMENTS
WHERE DEPT_NAME = 'APPLICATION DEVELOPMENT';
This will return all the records which satisfy the greater than condition i.e. with values greater than the value mentioned in the condition for that column. The values which are less or equal will not be included in the output.
SELECT * FROM SALARIES WHERE SALARY > 80000;
Here only the records with values less than the value mentioned are returned. The rest are not included in the output result set.
SELECT * FROM SALARIES WHERE SALARY < 39000;
All the records that have a value greater than or equal to the value mentioned in the condition will be included. The records with values less than the value mentioned for the column will not be included in the result set.
SELECT * FROM SALARIES WHERE SALARY >= 80000;
The records with values less than or equal to the value mentioned will be included in the result set.
SELECT * FROM SALARIES WHERE SALARY <= 80000;
To check Null conditions, we do:
SELECT * FROM EMPLOYEES WHERE HIRE_DATE IS NULL;
Only the records with No Null values are returned in the result set. The NULL values for that column are excluded.
SELECT * FROM EMPLOYEES WHERE HIRE_DATE IS NOT NULL;
There are many other options we can use with the where Clause and make massive, complex queries. We will look at those examples in further articles.