Planet MySQL Planet MySQL: Meta Deutsch Español Français Italiano 日本語 Русский Português 中文
Showing entries 1 to 5

Displaying posts with tag: outer join (reset)

MySQL NATURAL JOIN Tutorial & Examples
+0 Vote Up -0Vote Down

This tutorial explains how you can use NATURAL JOINs and what a natural join is actually. Included are syntax details and example statements.

Generally speaking, the keyword NATURAL can be treated as a join condition which is added implicitly. If used, it replaces the keywords ON and USING altogether. In MySQL writing natural joins means adding the keyword NATURAL to either an INNER JOIN or an OUTER JOIN. Let’s take a look at how a natural join implies a join condition.

Syntax

First of all, some natural join syntax examples. As mentioned earlier, a natural join adds a implicit condition to inner and outer join statements:

-- natural inner join
SELECT

  [Read more...]
MySQL RIGHT OUTER JOIN Tutorial & Examples
+0 Vote Up -0Vote Down

Here you find information about writing RIGHT JOINs (also referred to as RIGHT OUTER JOINs). This introduction into right joins includes a detailed description, syntax information and right outer join example statements. The Venn diagram on the left represents a result set that a statement with a right join produces. Please refer to the syntax examples below for an example. Links to additional information resources can be found at the end of this article.


Right Join syntax

First of all, some syntax examples for the impatient:

-- right join with USING-clause
SELECT *
FROM <leftTable> RIGHT JOIN <rightTable>
USING(id)


  [Read more...]
MySQL LEFT OUTER JOIN Tutorial & Examples
+0 Vote Up -0Vote Down

Here you find information about writing LEFT JOINs (also referred to as LEFT OUTER JOINs). This introduction into left joins includes a description, syntax information and example statements that use left outer joins. The Venn diagram on the left represents a result set that a statement with a left join produces. Please refer to the syntax examples below for an example. Links to additional information resources can be found at the end of this article.

Left Join syntax

First of all, some syntax examples for the impatient:

-- left join with USING-clause
SELECT *
FROM <leftTable> LEFT JOIN <rightTable>
USING(id)
-- left join with ON-clause
SELECT *
FROM


  [Read more...]
MySQL OUTER JOIN Tutorial & Examples
+0 Vote Up -0Vote Down

Here you find information about OUTER JOINs in MySQL statements. This tutorial is a general introduction. Syntax details and example statements are split into a LEFT OUTER JOIN tutorial and RIGHT OUTER JOIN tutorial because these are specific outer joins. 

Outer Join basics

MySQL (http://www.mysql.com/) supports outer joins. They identify matching rows that are stored in two different tables and add the selected columns to the result set. That’s exactly what an inner join does as well.

The difference between inner and outer join is: An outer join can identify rows without a match in the joined table. When no match was found, MySQL sets the value


  [Read more...]
Good SQL Querying
+0 Vote Up -0Vote Down

By “Good SQL Querying”, I am not referring to “how to make your queries more perfomant.” I am about to go on a mini-rant about how to make readable and self-documenting SQL queries.

One practice that will get me instantly going on a rant is using a comma join. There is NO reason to do the following:

-- uses the sakila sample database
SELECT first_name, last_name, address
FROM customer,address;

What kind of join did the original author intend? A CROSS JOIN? Or did they really want an INNER JOIN and forget the WHERE clause?

The answer: you do not know for sure; you can only guess. Had the query been

SELECT first_name,last_name,address
FROM customer INNER JOIN address;

you would know that the author intended an INNER JOIN; had the query been

SELECT first_name,last_name,address
FROM customer CROSS JOIN
  [Read more...]
Showing entries 1 to 5

Planet MySQL © 1995, 2014, Oracle Corporation and/or its affiliates   Legal Policies | Your Privacy Rights | Terms of Use

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.