Mysql Joins
Mysql Joins
A JOIN clause is used to combine rows from two or more tables, based on a related column between
them.
1. Cross join
2. Inner join
3. Left join
4. Right join
5. Natural join
6. Straight_join
For example, joining a 100-row table to a 200-row table produces a result containing 100 X 200, or
20,000 rows.
In the output column list, you can name columns from any or all of the joined tables, or use
expressions that are based on those columns
table_references:
escaped_table_reference:
table_reference
| { OJ table_reference }
table_reference:
table_factor
| join_table
table_factor:
| ( table_references )
join_table:
join_condition:
ON conditional_expr
| USING (column_list)
In MySQL, JOIN, CROSS JOIN, and INNER JOIN are syntactic equivalents (they can replace each other).
In standard SQL, they are not equivalent
A join enables you to retrieve records from two (or more) logically related tables in a single result
set.
JOIN clauses are used to return the rows of two or more queries using two or more tables that
shares a meaningful relationship based on a common set of values.
Select t1.col, t2.coln from table1 t1, table2 t2 where t1.co_coln_name= t2.co_coln_name and
[conditions]
Cross join and inner join are same, if you don’t specify any condition then cross, inner, simple join
produce a Cartesian product
Natural join with out condition produce a simple join with only matched columns, matched column
is displayed only once
On clause
INNER JOIN
LEFT JOIN
RIGHT JOIN
STRAIGHT JOIN
CROSS JOIN