27.10.2014 Views

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

<strong>Solutions</strong> to Chapter 15 | Databases<br />

2.1. LEFT OUTER JOIN, or simply LEFT JOIN: The result will contain all records from <strong>the</strong> left<br />

table. If no matching records were found in <strong>the</strong> right table, <strong>the</strong>n its fields will contain <strong>the</strong><br />

NULL values. In our example, we would get 4 records. In addition to INNER JOIN results,<br />

BUDWEISER will be listed, because it was in <strong>the</strong> left table.<br />

2.2. RIGHT OUTER JOIN, or simply RIGHT JOIN: This type of join is <strong>the</strong> opposite of LEFT<br />

JOIN; it will contain all records from <strong>the</strong> right table, <strong>and</strong> missing fields from <strong>the</strong> left table will<br />

contain NULL. If we have two tables A <strong>and</strong> B, <strong>the</strong>n we can say that statement A LEFT JOIN B<br />

is equivalent to statement B RIGHT JOIN A.<br />

In our example, we will get 5 records. In addition to INNER JOIN results, FRESCA <strong>and</strong> WATER<br />

records will be listed.<br />

2.3. FULL OUTER JOIN<br />

This type of join combines <strong>the</strong> results of LEFT <strong>and</strong> RIGHT joins. All records from both tables<br />

will be part of <strong>the</strong> result set, whe<strong>the</strong>r <strong>the</strong> matching record exists in <strong>the</strong> o<strong>the</strong>r table or not. If<br />

no matching record was found <strong>the</strong>n <strong>the</strong> corresponding result fields will have a NULL value.<br />

In our example, we will get 6 records.<br />

2 3 3<br />

<strong>Cracking</strong> <strong>the</strong> <strong>Coding</strong> <strong>Interview</strong> | Knowledge Based

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

Saved successfully!

Ooh no, something went wrong!