PostgreSQL Where Clause

PostgreSQL Where Clause is used to filter data from tables. i.e. where condition is any expression that evaluates to a result of type boolean.

1. Any row that does not satisfy this condition will be eliminated from the output.
2. A row satisfies the condition if it returns true when the actual row values are substituted for any variable references.
3. Where clause is used with SELECT, UPDATE and DELETE statements to filter the results.

PostgreSQL Where Clause Syntax:

SELECT columnslist from tablename WHERE condition1 AND/OR condtion2

PostgreSQL Where Clause Examples:

Lets work on following ’emp’ table for examples:

PostgreSQL Where Clause

1. Lets filter the emp table where name=’SMITH’
strings and dates must be mentioned in quotes.

select * from emp where ename='SMITH';

PostgreSQL Where Clause

2. Lets filter emp table where employee number(empno) equals to 7566

select * from emp where empno=7566;

3. Find the Employees who’s joined is between 1980-01-01 to 1981-06-30.
strings and dates must be mentioned in quotes.

select * from emp where hiredate between '1980-01-01' and '1981-06-30';

4. Find the employees whose job is SALESMAN.

select * from emp where job='SALESMAN';

5. Find the employees whose deptno=20.

select * from emp where deptno=20;

6. Find the employees whose job is MANAGER and deptno=30.
This is multi condition where clause.

select * from emp where job='MANAGER' and deptno=30;

7. Find the list of employees who is working either as ‘MANAGER’ or ‘CLERK’.

select * from emp where job='MANAGER' or job='CLERK';