PostgreSQL AND

PostgreSQL AND operator combines two Boolean expressions and returns TRUE when both expressions are TRUE.

PostgreSQL AND Syntax:

boolean_expression1 AND boolean_expression2

If both expressions are true, then only result set will give us rows.
If any one of them are false or both expressions are false, then result set contains zero rows.

PostgreSQL AND Examples:

Below table used for below examples:

1. select employees who is belongs to deptno 20 and job is ‘MANAGER’

SELECT * FROM emp where deptno =20 and job='MANAGER';

Output:

empno | ename | job | mgr | hiredate | sal | comm | deptno -------+-------+---------+------+------------+---------+--------+-------- 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | 300.00 | 20

2. Find the employees who belongs to deptno 10 and job is ‘MANAGER’.

SELECT * FROM emp where deptno =10 and job='MANAGER';

Result contains zero rows. Because both expressions are false.

3. Find the employees who joined after 1980-01-01 and before 1981-12-31.

select * from emp where hiredate between '1980-01-01' and '1981-12-31';