0% found this document useful (0 votes)
6 views6 pages

SQL Joins

The document provides an overview of SQL joins, which are used to combine rows from multiple tables based on related columns. It explains different types of joins including Left Join, Right Join, Inner Join, Full Join, Natural Join, and Self Join, detailing how each type operates and the results they produce. SQL joins are essential for retrieving and presenting data from various tables as a single result set.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

SQL Joins

The document provides an overview of SQL joins, which are used to combine rows from multiple tables based on related columns. It explains different types of joins including Left Join, Right Join, Inner Join, Full Join, Natural Join, and Self Join, detailing how each type operates and the results they produce. SQL joins are essential for retrieving and presenting data from various tables as a single result set.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Understanding SQL Joints Its Core Components

Introduction to SQL Joins


Left Join
Right Join
Full Join

Inner Join

Natural Join
Self Join
Introduction to SQL Joins
SQL joins are used to combine rows from two or more tables based on a
related column between them. Joins are fundamental in SQL and are
used to retrieve data from multiple tables and present it as a single result
set.

Left Join in SQL


Left Join is a type of join in SQL that returns all records from the left
table and the matched records from the right table.
Returns all rows from the left table and matching rows from the right
table. If no match is found, NULL values are included for columns from
the right table.

All departments are returned, and employees are matched where


possible. For departments without a matching employee, NULL values
are shown for name.
Right Join in SQL
Right Join is a type of join in SQL that returns all records from the right
table and the matched records from the left table. If there is no match,
the result is NULL on the side of the left table.

Returns all rows from the right table and matching rows from the left
table. If no match is found, NULL values are included for columns from
the left table.

All departments are returned, and employees are matched where


possible. For departments without a matching employee, NULL values
are shown for name.

Inner Join in SQL


Inner Join is a type of join in SQL that returns only the rows that have
matching values in both tables involved in the join. Returns rows that
have matching values in both tables being joined.

Only the employees who have a corresponding department


in the departments table are returned,
Full Join in SQL
Full Join (also known as Full Outer Join) is a type of join in SQL that
returns all records when there is a match in either the left table or
the right table. If there is no match, the result is NULL from the table
that lacks a matching row.

All employees and departments are returned, regardless of whether


they have a matching row in the other table. If an employee doesn't
belong to a department, the department_name will be NULL, and if a
department doesn't have any employees, the name will be NULL.

Natural Join in SQL


Natural Join is a type of join in SQL that automatically joins tables
based on columns with the same name and data type in both tables.
Joins tables using all columns with the same name and data type,
eliminating the need to specify the joining columns explicitly.

Employees and departments tables are joined based on all


columns with matching names and data types.
Self Join in SQL
Self Join is a type of join in SQL where a table is joined with itself.
Joins a table with itself to compare rows within the same table.

employees a and employees b are aliases for the same table.


The join matches employees with their managers by comparing
a.manager_id with b.employee_id.

You might also like