While writing SQL queries we are required to insert many conditions, functions and joins to fetch the records from one or multiple tables of database. In case of multiple conditions, many operators in SQL are used in a single query.
The “AND operator” in SQL is among one of those operators which is used to link more than one conditional statements in our query. In this tutorial we will learn the usage of this operator.
Step 1- All Records
The usage of AND operator in SQL would be better understood by viewing all records of any table first.
For that, in the Query Editor write:
select * from emp
and execute it.
Step 2- Applying and Operator
Now let’s start filtering out the results.
For that, first we will add the Where clause, filtering out the results through the Job column, and only displaying the results of those employees who are managers.
Further, let’s filter out the results and display the records of only those managers which are hired at a certain pay scale. For that, insert AND keyword and specify Salary greater than the required amount let’s say 2450 in our case.
Now the query would be:
select * from emp
where JOB=’manager’
AND
sal >2450
And this is how we can use and operators in SQL.