MySQL Join Query
What is Join Query

By Join Query we select data from multiple tables. Basically we can say Join has Four Type

1- Inner Join
2- Outer Join(Left outer join, right outer join)
3- Self Join
4- Cross Join

Inner Join

It return the records that match value in both tables

SELECT column1, column2 FROM table1 INNER JOIN table2
ON table1.column = table2.column;

Left Outer Join

It return the records that match value from left side table. Means left side table display all record and match record to right side table will be display.

SELECT column1, column2 FROM table1 LEFT JOIN table2
ON table1.column = table2.column;

Right Outer Join

It return the records that match value from Right side table. Means Right side table display all record and match record to left side table will be display.

SELECT column1, column2 FROM table1 RIGHT JOIN table2
ON table1.column = table2.column;

Self Join

In Self Join we join table itself

SELECT t1.column1, t2.column2 FROM table1 t1 ,table1 t2
where t1.column = t2.column;

Cross Join

This is like cartesian product, It produce number of rows from first table multiply by second table.
Means if first table have 5 record and second have 10 record then this return 15Record

SELECT column1, column2
FROM table1 CROSS JOIN table2


Previous