MySQL Joins
MySQL Joins
MySQL Joins
MySQL Joins
MySQL Joins Overview
• MySQL Join is used to join the records from two table using
join clause.
• The Join Clause return you the set of records from both table
on the basis of common column.
• The Join return you only match able records from both table
on the basis of where clause .
MySQL Join Types
• mysql> select
emp.firstname,emp.city,peson.firstname,person.email
from emp,person where emp.empid=person.empid;
MySQL Equi Join
• Equi Join is a classified type of Inner Join in Mysql.
• Equi Join is used to combine records from two table based on
the common column exists in both table.
• The Equi Join returns you only those records which are
available in both table on the basis of common primary field
name.
• mysql> select emp.firstname,emp.city,contact.phone from
employee,contact where emp.empid=contact.empid;
MySQL Natural Join
• MySQL Natural Join is a specialization of equi-joins.
• The join compares all columns in both tables that
have the same column-name in both tables that have
column name in the joined table.
• Syntax:
• SELECT a.column_name, b.column_name... FROM table1 a,
table1 b WHERE a.common_filed = b.common_field;
MySQL Self Join
• id first_ name last_name manager
--- --------------- --------------- ---------------
• 1 Pat Crystal NULL
2 Dennis Miller 1
3 Jacob Smith 1
4 Allen Hunter 2
5 Mary Underwood 3
6 Joy Needham 3
MySQL Self Join
• In this table, the manager attribute simply references
the employee ID of another employee in the same
table.