Joins
Joins
Introduction
The MySQL Joins clause is used to combine records from
two or more tables in a database.
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.
Ex:
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 :
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 :
A full outer join combines the effect of applying both left and
right outer joins.
Ex :
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 :
Syntax :
select * from table_name1,table_name2
where a.column_name=b.column_name;
Example: