February 23rd, 2009

FULL OUTER JOIN

Posted by admin in L. JOINs

A FULL OUTER JOIN includes all rows from the left table and all rows from the right table. Any table rows without matching table rows from the other table will have nulls returned for the missing selected values.

                                                  FULL OUTER JOIN syntax:

                                      SELECT t1.column1 AS ‘title1′, 
                                                   t2.column2 AS ‘title2′, …
                                         FROM left_table                          [AS] ‘t1′
                                          FULL [OUTER] JOIN right_table [AS] ‘t2′
                                             ON left_t1.column1 oper right_t2.column2[, ...]
                                     [GROUP BY t1.column1]
                                     [HAVING      t1.column1]
                                     [ORDER BY t1.column1 [ASC|DESC]]

If the tables have common column names, those column names must be qualified with the table name or alias as follows: [left_table.]column oper [right_table.]column.

> While FULL OUTER JOINs can be done occasionally without the key word OUTER, the word OUTER should normally be included in the OUTER JOIN statement for clarity of understanding.

> Access and MySQL do not support FULL OUTER JOIN, but it can be done with a UNION ALL.

> Oracle 9i and later supports the FULL OUTER JOIN, but it also has the non-standard (+) outer join operator.

> SQL Server supports FULL OUTER JOIN, but it also has the non-standard outer join * in the WHERE syntax.

February 20th, 2009

RIGHT OUTER JOIN

Posted by admin in L. JOINs

A RIGHT OUTER JOIN includes all rows from the right table and all matching rows from the left table. Any right table rows without matching left table rows will have nulls returned for the missing selected values. The order of tables in a RIGHT OUTER JOIN are critical and can not be rearranged.

                                              RIGHT OUTER JOIN syntax:

                                    SELECT t1.column1 AS ‘title1′,
                                                 t2.column2 AS ‘title2′, …
                                       FROM left_table [AS] ‘t1′
                                      RIGHT [OUTER] JOIN right_table [AS] ‘t2′
                                           ON left_t1.column1 oper right_t2.column2[, ...]
                                   [GROUP BY t1.column1] 
                                   [HAVING      t1.column1] 
                                   [ORDER BY t1.column1 [ASC|DESC]]

If the tables have common column names, those column names must be qualified with the table name or alias as follows: [left_table.]column oper [right_table.]column.

> While RIGHT OUTER JOINs can be done occasionally without the key word OUTER, the word OUTER should normally be included in the OUTER JOIN statement for clarity of understanding.

> Oracle 9i and later supports the OUTER JOIN, but it also has the non-standard (+) outer join operator.

> SQL Server supports OUTER JOIN, but it also has the non-standard outer join * in the WHERE syntax.

February 19th, 2009

LEFT OUTER JOIN

Posted by admin in L. JOINs

A LEFT OUTER JOIN includes all rows from the left table and all matching rows from the right table. Any left-table rows without matching right-table rows will have nulls returned for the missing selected values. The order of tables in a LEFT OUTER JOIN are critical and can not be rearranged.

                                               LEFT OUTER JOIN syntax:

                                   SELECT t1.column1 AS ‘title1′,
                                                t2.column2 AS ‘title2′, …
                                      FROM left_table                         [AS] ‘t1′
                                       LEFT [OUTER] JOIN right_table [AS] ‘t2′
                                          ON left_t1.column1 oper right_t2.column2[, ...]
                                  [GROUP BY t1.column1]
                                  [HAVING      t1.column1]
                                  [ORDER BY t1.column1 [ASC|DESC]]

If the tables have common column names, those column names must be qualified with the table name or alias as follows: [left_table.]column oper [right_table.]column.

> While LEFT OUTER JOINs can be done occasionally without the key word OUTER, the word OUTER should normally be included in the OUTER JOIN statement for clarity of understanding.

> Oracle 9i and later supports the LEFT OUTER JOIN, but it also has the non-standard (+) outer join operator.

> SQL Server supports LEFT OUTER JOIN, but it also has the non-standard outer join * in the WHERE syntax.

Next Page »