0% found this document useful (0 votes)
20 views16 pages

Joins

Uploaded by

Balasubramanian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views16 pages

Joins

Uploaded by

Balasubramanian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

JOINS

Introduction
The MySQL Joins clause is used to combine records from
two or more tables in a database.

A JOIN is a means for combining fields from two tables


by using values common to each.

 MySQL Joins are used to relate information


in different tables.
A Join condition is a part of the sql query that
retrieves rows from two or more tables.

 A MySQL Join condition is used in the


MySQL WHERE Clause of select, update,
delete statements.
Types of Joins:

 Inner join
 Right outer join
 Left Outer join
 Full join
 Cross join
Inner join
An 'inner join' is a commonly used join operation used in
applications.

Inner join creates a new result table by combining column


values of two tables (A and B) based upon the join-predicate.

When the join-predicate is satisfied, column values for each


matched pair of rows of A and B are combined into a result
row.
Syntax :

Select * from <tablename 1> inner join <tablename 2> on


Tablename 1.column name =tablename 2.column name;

Ex:

Select * from employee inner join department on employee.did


= department.did;
Left outer join
left outer join (or simply left join) for tables A and B always
contains all records of the "left" table (A) , even if the join-
condition does not find any matching record in the "right" table
(B).

The join will still return a row in the result (for that record)—
but with NULL in each column from B.

A left outer join returns all the values from an inner join plus
all values in the left table that do not match to the right table.
 Syntax :
select * from <tablename 1> left outer join <tablename 2> on
Table name 1. column name = tablename 2. column name;

Ex :

select * from employee left outer join department on


employee . did= department . did;
Right outer join
 A right outer join (or right join) closely resembles a left outer join,
except with the treatment of the tables reversed.

 Every row from the "right" table (B) will appear in the joined table at
least once.

 If no matching row from the "left" table (A) exists, NULL will
appear in columns from A for those records that have no match in B.
 Syntax :
select * from <tablename 1> right outer join <tablename 2> on
Table name 1. column name = tablename 2. column name;

Ex :

select * from employee right outer join department on


employee . did= department . did;
Full outer join

A full outer join combines the effect of applying both left and
right outer joins.

Where records in the FULL OUTER JOINed tables do not


match, the result set will have NULL values for every column
of the table that lacks a matching row.
 Syntax :
select * from <tablename 1> full outer join <tablename 2> on
Table name 1. column name = tablename 2. column name;

Ex :

select * from employee full outer join department on


employee . did= department . did;
Cross Join

CROSS JOIN returns the Cartesian product of rows from


tables in the join.

In other words, it will produce rows which combine each row
from the first table with each row from the second table.
 Syntax :
select * from <tablename 1> cross join <tablename 2;

Ex :

select * from employee cross join department;


SELF JOIN
 The SELF JOIN is used to join a table to itself as if the
table were two tables, temporarily renaming at least one
table in the MySQL statement.

Syntax :
select * from table_name1,table_name2
where a.column_name=b.column_name;
Example:

select * from employee,department where


employee.did = department.did;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy