PostgreSQL Where clause : Part 2

  • Post comments:0 Comments
  • Reading time:4 mins read
  • Post category:SQL

In the previous post we learned about PostgreSQL where clause introduction, In this post, we learn more about restricting the rows using different types of using where clause in postgreSQL with examples.

when retrieving data from the database, you may need to do the following.

1. restrict the rows of data that are displayed.
2. specify the order in which the rows are displayed

Following are the different ways where we use where clause in PostgreSQL.

comparison operators in PostgreSQL where clause

comparison operators are used in conditions that compare one expression to another value. They are used in the where clause in the following format.

Following are the comparison operators

Operator Meaning
———— —————–
=                Equal to
>                Greater than
>=             Greater than or equal to
<                Less than
<=             Less than or equal to
<>             Not equal to

syntax:

where expression operator value

e.g., where sal > 4000

Example.,

The BETWEEN Operator

You can display rows based on a range of values using the BETWEEN operator. The range that you specify contains a lower
range and an upper range.

Values specified with the BETWEEN operator are inclusive. You must specify the lower limit first.
If you want to display all the employees whose salary is between 1200 and 2000, use the below query.

select * from emp where sal between 1200 and 2000;

IN operator in SQL where clause:

The IN clause is used to display the records that match the values that are set in IN condition.

syntax

where expression IN (‘value1′,’value2’..);

Example.,

PostgreSQL where date is today:

PostgreSQL where not equal:

PostgreSQL where multiple conditions

Leave a Reply