|Retrieving Data from Multiple Tables with SQL Joins|
|Part 1: Introducing Joins|
In several recent articles we explored the fundamental concepts of SQL, the process of creating databases and database tables and the art of retrieving data from a database using simple queries. This article expands on these topics and looks at using join techniques to retrieve data from multiple tables.
By way of example, let's return to our fictitious XYZ Corporation. XYZ utilizes an Oracle database to track the movements of their vehicle fleet and drivers between their facilities. Some employees are assigned to drive trucks while others are assigned to drive cars. Take a moment to examine the following two tables from their vehicle management database:
In the previous article, we looked at methods used to retrieve data from single tables. For example, we could use simple SELECT statements to answer questions such as:
Practical applications often require the combination of data from multiple tables. Our vehicle managers might make requests like the following:
Granted, it would be possible to create complex SELECT statements using subqueries to fulfill these requests. However, there's a much simpler method -- the use of inner and outer joins. We'll explore each of these concepts in the next two sections of this article. Read on!