Oracle SQL in 10 Minutes - Asim Abbasi

CH1: SQL Basics | CH2:  SQL Operators | CH3:  SQL Built-in Functions | CH4: SQL Joins | CH5: UPDATE, INSERT & DELETE Statements | CH6: CREATE, ALTER & DROP Statements | CH7: Constraints | CH8: Linking Tables vs Joining Tables | CH9: SQL Statements for Other Database Objects | CH10: SQL Statements for Database Security

Chapter 4: SQL Joins

Page #: 1 | 2 | 3 | 4

Outer-Join:

If you ask me what is the most important thing in SQL and my response will always be “Outer Join”. This is because it has very high practical value. It has been used a lot in the real world wherever SQL is utilized. I want you to cram/memorize its definition word by word. I will first give you its definition and explanation will follow afterwards.

 

Figure 10: Outer Join: The plus (+) sign is used to join two tables.
________________________________________

 

Outer Join will give you all the records from the first table and only those records from the second table where there is a match.

It means that the total number of records in the result will be equal to the number of records of the one table among the two having no positive sign (+) attached with its column name in the WHERE clause. In other words, the way you create an Outer join is very simple. First create a Equijoin query and then place the positive sign (+) with the column name of the table having least number of records, in the WHERE clause.

I would like to have your focus on the NULL (empty) values in the Figure 10; the one shown in the output table. These order dates are NULL because there were no supplier ids 10002 & 10003 in the orders table.

Chapter 4: SQL Joins

Page #: 1 | 2 | 3 | 4

CH1: SQL Basics | CH2:  SQL Operators | CH3:  SQL Built-in Functions | CH4: SQL Joins | CH5: UPDATE, INSERT & DELETE Statements | CH6: CREATE, ALTER & DROP Statements | CH7: Constraints | CH8: Linking Tables vs Joining Tables | CH9: SQL Statements for Other Database Objects | CH10: SQL Statements for Database Security

Share with others: