

MySQL's GROUP BY clause enables programmers to organize data based on one or more columns. We have a table called suppliers with two fields (supplier_id and supplier_name).Data grouping is one of the most frequent actions that developers carry out on databases. Let's look at some data to explain how RIGHT OUTER JOINS work: If a supplier_id value in the orders table does not exist in the suppliers table, all fields in the suppliers table will display as in the result set. This RIGHT OUTER JOIN example would return all rows from the orders table and only those rows from the suppliers table where the joined fields are equal. Here is an example of a MySQL RIGHT OUTER JOIN: SELECT orders.order_id, orders.order_date, suppliers.supplier_name The MySQL RIGHT OUTER JOIN would return the all records from table2 and only those records from table1 that intersect with table2. In this visual diagram, the MySQL RIGHT OUTER JOIN returns the shaded area:

In some databases, the RIGHT OUTER JOIN keywords are replaced with RIGHT JOIN. The syntax for the RIGHT OUTER JOIN in MySQL is: SELECT columns

This type of join returns all rows from the RIGHT-hand table specified in the ON condition and only those rows from the other table where the joined fields are equal (join condition is met). Let's look at some data to explain how LEFT OUTER JOINS work:Īnother type of join is called a MySQL RIGHT OUTER JOIN. If a supplier_id value in the suppliers table does not exist in the orders table, all fields in the orders table will display as in the result set. This LEFT OUTER JOIN example would return all rows from the suppliers table and only those rows from the orders table where the joined fields are equal. Here is an example of a MySQL LEFT OUTER JOIN: SELECT suppliers.supplier_id, suppliers.supplier_name, orders.order_date The MySQL LEFT OUTER JOIN would return the all records from table1 and only those records from table2 that intersect with table1. In this visual diagram, the MySQL LEFT OUTER JOIN returns the shaded area: In some databases, the LEFT OUTER JOIN keywords are replaced with LEFT JOIN. The syntax for the LEFT OUTER JOIN in MySQL is: SELECT columns This type of join returns all rows from the LEFT-hand table specified in the ON condition and only those rows from the other table where the joined fields are equal (join condition is met). It contains the following data:Īnother type of join is called a MySQL LEFT OUTER JOIN. We have a table called suppliers with two fields (supplier_id and supplier_name). Let's look at some data to explain how the INNER JOINS work: This MySQL INNER JOIN example would return all rows from the suppliers and orders tables where there is a matching supplier_id value in both the suppliers and orders tables.

ON suppliers.supplier_id = orders.supplier_id Here is an example of a MySQL INNER JOIN: SELECT suppliers.supplier_id, suppliers.supplier_name, orders.order_date The MySQL INNER JOIN would return the records where table1 and table2 intersect. In this visual diagram, the MySQL INNER JOIN returns the shaded area: The syntax for the INNER JOIN in MySQL is: SELECT columns MySQL INNER JOINS return all rows from multiple tables where the join condition is met. Chances are, you've already written a statement that uses a MySQL INNER JOIN.
