PostgreSQL Non-Equi Join

PostgreSQL Non-Equi Join performs when 2 tables are not sharing a common column. This join is not based on equal operator. It is based on >=,<=, or between operator.

PostgreSQL Non-Equi Join Examples:

Tables used for below examples:

emp table:

salgrade table:

grade | lowsal | highsal -------+--------+--------- 1 | 1000 | 2000 2 | 2000 | 3000 3 | 3000 | 4000 4 | 4000 | 5000

1. Display employees empno, name, salary and their grades.

select e.empno,e.ename,e.sal,s.grade from emp e, salgrade s where e.sal between s.lowsal and s.highsal;

PostgreSQL Non-Equi Join

2. Display employees empno, name, salary and their department names and grades.

select e.empno, e.ename,e.sal,d.dname,s.grade from emp e join dept d on e.deptno=d.deptno join salgrade s on e.sal between s.lowsal and s.highsal;

empno | ename | sal | dname | grade -------+--------+---------+------------+------- 7521 | WARD | 1250.00 | SALES | 1 7369 | SMITH | 1300.00 | RESEARCH | 1 7654 | MARTIN | 1250.00 | SALES | 1 7934 | MILLER | 1800.00 | ACCOUNTING | 1 7499 | ALLEN | 1600.00 | SALES | 1 7566 | JONES | 2975.00 | RESEARCH | 2 7698 | BLAKE | 2850.00 | SALES | 2