PostgreSQL Inner Join

PostgreSQL Inner Join is also called equi join. Inner join can be performed if two or more tables are having a common column.
Name of the column need not to be same and primary key, foreign key relationship not compulsory.

PostgreSQL Inner Join Syntax

SELECT table1.column1, table2.column2... FROM table1 INNER JOIN table2 ON table1.common_field = table2.common_field;

PostgreSQL Inner Join Examples:

Tables used for below examples:

emp table:

dept table:

deptno | dname | loc --------+------------+---------- 40 | OPERATIONS | BOSTON 30 | SALES | CHICAGO 10 | ACCOUNTING | NEW YORK 20 | RESEARCH | DALLAS

1. Display employee details with dept details who’s working location is ‘NEW YORK’.

select e.empno,e.ename,e.sal, d.dname,d.loc from emp e join dept d on e.deptno=d.deptno where d.loc='NEW YORK';

2. Display the employees whose salary is greater than 2000 and work location is ‘CHICAGO’.

select e.empno,e.ename,e.sal, d.dname,d.loc from emp e join dept d on e.deptno=d.deptno and e.sal>2000 and d.loc='CHICAGO';