Equi-Join

Equi-Join:

Consider two tables: employees and departments. Both tables have a common column named department_id.

Table: employees

employee_id

employee_name

department_id

salary

1

Alice

101

5000

2

Bob

102

6000

3

Charlie

101

5500

4

David

103

7000

Table: departments

department_id

department_name

101

HR

102

IT

103

Finance

SQL Equi-Join Query

SELECT employees.employee_id, employees.employee_name, employees.salary, departments.department_name FROM employees JOIN departments ON employees.department_id = departments.department_id;

 Result:

employee_id employee_name salary department_name
1 Alice 5000 HR
2 Bob 6000 IT
3 Charlie 5500 HR
4 David 7000 Finance

 In this example, the JOIN keyword is used to combine rows from the employees table with the matching rows from the departments table based on the common column department_id. The result includes columns from both tables where the join condition is satisfied. This type of join is known as an equi-join because it uses equality comparison in the join condition.

No comments:

Post a Comment