quick links

MySQL Join

JOIN or INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, SELF JOIN, CROSS JOIN, UNION JOIN. These are all

JOIN or INNER JOIN

  • INNER JOIN returns rows when there is at least one match in both tables.
  • SELECT * FROM employee a INNER JOIN salary b on a.employee_id = b.employee_id_ref

LEFT JOIN

  • Return all rows from the left table, even if there are no matches in the right table.
  • SELECT * FROM employee a LEFT JOIN salary b on a.employee_id = b.employee_id_ref

RIGHT JOIN

  • Return all rows from the right table, even if there are no matches in the left table
  • SELECT * FROM employee a RIGHT JOIN salary b on a.employee_id = b.employee_id_ref

FULL JOIN or OUTER JOIN

  • The FULL OUTER JOIN keyword return all records when there is a match in either left (table1) or right (table2) table records.
  • SELECT * FROM employee a FULL JOIN salary b on a.employee_id = b.employee_id_ref

SELF JOIN

  • In SELF JOIN table is joined with itself
  • SELECT a.column_name, b.column_name... FROM table1 a, table1 b WHERE a.common_field = b.common_field;

CROSS JOIN

  • The SQL CROSS JOIN produces a result set which is the number of rows in the first table multiplied by the number of rows in the second table. If no WHERE clause is used along with CROSS JOIN.This kind of result is called as Cartesian Product.
  • SELECT store_name, product_name FROM stores AS a CROSS JOIN products AS b;

UNION JOIN

  • Combine two or more result sets of multiple queries into a single result set.
  • SELECT id FROM t1 UNION SELECT id FROM t2;
 

About Us

Joomla Web Solution

We love working with PHP, HTML5, CSS3, jQuery and the most-loved content management framework in the world, Joomla!

LIKE US ON FACEBOOK