0% found this document useful (0 votes)
21 views2 pages

6.SQL JOINS Operations

The document provides an overview of SQL JOIN operations used to combine data from multiple tables based on related columns. It describes various types of joins including INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, CROSS JOIN, and SELF JOIN, along with their functionalities. Sample SQL queries are provided to illustrate each type of join using 'employees' and 'departments' tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

6.SQL JOINS Operations

The document provides an overview of SQL JOIN operations used to combine data from multiple tables based on related columns. It describes various types of joins including INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, CROSS JOIN, and SELF JOIN, along with their functionalities. Sample SQL queries are provided to illustrate each type of join using 'employees' and 'departments' tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

/*SQL JOINS: -- SQL JOIN operations are used to combine data from two or more

tables based on a related column between them.

Types SQL JOINS :

INNER JOIN
LEFT JOIN (LEFT OUTER JOIN)
RIGHT JOIN (RIGHT OUTER JOIN)
FULL JOIN (FULL OUTER JOIN)
CROSS JOIN
SELF JOIN
*/

select * from employees; -- 72 ROWS

select * from departments; -- 14 ROWS

select distinct department_id from employees;

select
employee_name,employee_salary,departments.department_name,departments.department_id
from employees INNER JOIN departments on employees.department_id =
departments.department_id;

select
employee_name,employee_salary,departments.department_name,departments.department_id
from employees LEFT JOIN departments on employees.department_id =
departments.department_id;

select
employee_name,employee_salary,departments.department_name,departments.department_id
from employees RIGHT JOIN departments on employees.department_id =
departments.department_id;

select
employee_name,employee_salary,departments.department_name,departments.department_id
from employees FULL JOIN departments on employees.department_id =
departments.department_id;

select
employee_name,employee_salary,departments.department_name,departments.department_id
from employees CROSS JOIN departments;

/*
1. INNER JOIN : An INNER JOIN returns only the rows where there is a relative
column match between the tables. If the columns data are not matched, then the
respective row is not included in the result

2. LEFT JOIN (LEFT OUTER JOIN) : A LEFT JOIN returns all rows from the left
table and the matched rows from the right table. If the relative columns are not
matched, NULL is returned from the right table.

3. RIGHT JOIN (RIGHT OUTER JOIN) : A RIGHT JOIN returns all the rows from the
right table and only the matched rows from the left table. If the relative columns
are not matched, NULL is returned from the left table.

4. FULL JOIN : A FULL JOIN returns all rows from both tables. If the relative
column is not matched, NULL is returned either

5. CROSS JOIN : A CROSS JOIN returns the Cartesian product of the two tables.
Every row from the first table is combined and multiplied with every row from the
second table. It returns m * n rows.

6. SELF JOIN : A SELF JOIN is used to join a table with itself. This is useful
when there is a hierarchy within a table.

*/

You might also like