Comparison Operators

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PostgreSQL Comparison Operators

Comparison Operators

Comparison operators, as their name, allows to comparing two values. It Compares strings or numbers for relationships such as equality.

List of Comparison Operators

Operators Description
< ( less than) Returns true when the left operand is less than the right operand.
> ( greater than) Returns true when the left operand is greater than the right operand.
<= ( less than or equal ) Returns true when the left operand is less than or equal to the right operand.
>= (greater than or equal) Returns true when the left operand is greater than or equal to the right operand.
= ( equal ) Returns true when the operands are equal but the type of the operands must be same.
<> or != ( not equal) Returns true when the operands are not equal.

PostgreSQL Less Than ( < ) operator example

If we want to display the list of employees with columns empno, emp_first_name, designame and salary from an employee who drawn the salary amount less than 10000, the following SQL can be used.

SQL

  1. SELECT empno,emp_first_name,designame,salary  
  2. FROM employee  
  3. WHERE salary<10000;  

PostgreSQL Greater Than ( > ) operator example

If we want to display the list of employees with columns empno, emp_first_name,designame and salary from an employee who drawn the salary amount more than 18000, the following SQL can be used.

SQL

  1. SELECT empno,emp_first_name,designame,salary  
  2. FROM employee  
  3. WHERE salary>18000; 

PostgreSQL Greater Than or Equal( >= ) and Less Than or Equal( <= ) operator example

If we want to display the list of employees with columns empno, emp_first_name, emp_last_name,designame and dt_birth from an employee who born between the period 1975-01-01 and 1982-03-31, the following SQL can be used.

SQL

  1. SELECT empno,emp_first_name,emp_last_name,designame,dt_birth  
  2. FROM employee  
  3. WHERE  dt_birth>='1975-01-01'  
  4. AND dt_birth<='1982-03-31';  

PostgreSQL Equal ( = ) operator example

If we want to display the list of employees with columns empno, emp_first_name, emp_last_name and designation from employee table whose designation is 'CLERCK', the following SQL can be used.

SQL

  1. SELECT empno,emp_first_name,emp_last_name,designame  
  2. FROM employee  
  3. WHERE  designame='CLERCK';  

PostgreSQL Not Equal (<> or != ) operator example

If we want to display the list of employees with columns empno, emp_first_name, emp_last_name and designation from employee table who does not belong to the designation 'CLERCK' and 'SALESMAN', the following SQL can be used.

SQL

  1. SELECT empno,emp_first_name,emp_last_name,designame  
  2. FROM employee  
  3. WHERE  designame<>'CLERCK'  
  4. AND designame<>'SALESMAN';