DEV Community

Mahabubur Rahman
Mahabubur Rahman

Posted on

SQL Types of Joining

Create Two Table

1) Department Table

CREATE TABLE
    department (
        department_id INT PRIMARY KEY,
        department_name VARCHAR(100)
    );
Enter fullscreen mode Exit fullscreen mode

SELECT * from department;

2) Employee Table

CREATE TABLE
    employee(
        employee_id INT PRIMARY KEY,
        full_name VARCHAR(100),
        department_id INT,
        job_role VARCHAR(100),
        manager_id INT,
        FOREIGN KEY (department_id) REFERENCES department(department_id)
    );
Enter fullscreen mode Exit fullscreen mode

SELECT * FROM employee;

We can join tables on six types.

  • Inner Join
  • Left Join
  • Right Join
  • Full Join
  • Natural Join
  • Cross Join

1 > Inner Join

SELECT *
FROM employee
    INNER JOIN department ON department.department_id = employee.department_id;
Enter fullscreen mode Exit fullscreen mode

2 > Left Join

SELECT *
FROM employee
    LEFT JOIN department ON department.department_id = employee.department_id;
Enter fullscreen mode Exit fullscreen mode

3 > Left Join

SELECT *
FROM employee
    RIGHT JOIN department ON department.department_id = employee.department_id;
Enter fullscreen mode Exit fullscreen mode

4 > Full Join

SELECT *
FROM employee
    FULL JOIN department ON department.department_id = employee.department_id;
Enter fullscreen mode Exit fullscreen mode

5 > Natural Join

SELECT * FROM employee NATURAL JOIN department;
Enter fullscreen mode Exit fullscreen mode

6 > Natural Join

SELECT * FROM employee CROSS JOIN department;
Enter fullscreen mode Exit fullscreen mode

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more