11.07.2015 Views

SQL Reference Volume 1 - Ibm

SQL Reference Volume 1 - Ibm

SQL Reference Volume 1 - Ibm

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Examples of joinsSELECT * FROM J1, J2 WHERE W=YThe following left outer join will get back the missing row from J1 with nulls forthe columns of J2. Every row from J1 is included.SELECT * FROM J1 LEFT OUTER JOIN J2 ON W=YW X Y Z--- ------ --- ------A 11 A 21B 12 - -C 13 C 22The following right outer join will get back the missing row from J2 with nulls forthe columns of J1. Every row from J2 is included.SELECT * FROM J1 RIGHT OUTER JOIN J2 ON W=YW X Y Z--- ------ --- ------A 11 A 21C 13 C 22- - D 23The following full outer join will get back the missing rows from both J1 and J2with nulls where appropriate. Every row from both J1 and J2 is included.SELECT * FROM J1 FULL OUTER JOIN J2 ON W=YW X Y Z--- ------ --- ------A 11 A 21C 13 C 22- - D 23B 12 - -Example B2: Using the tables J1 and J2 from the previous example, examine whathappens when and additional predicate is added to the search condition.SELECT * FROM J1 INNER JOIN J2 ON W=Y AND X=13W X Y Z--- ------ --- ------C 13 C 22The additional condition caused the inner join to select only 1 row compared to theinner join in “Example B1” on page 532.Notice what the impact of this is on the full outer join.SELECT * FROM J1 FULL OUTER JOIN J2 ON W=Y AND X=13W X Y Z--- ------ --- ------- - A 21C 13 C 22- - D 23A 11 - -B 12 - -The result now has 5 rows (compared to 4 without the additional predicate) sincethere was only 1 row in the inner join and all rows of both tables must bereturned.Chapter 5. Queries 533

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!