Join Bill Weinman for an in-depth discussion in this video Understanding joins, part of SQL Essential Training.
- View Offline
- Exercise Files
It's the nature of a relational database that some tables contain information related to other tables. Using the join statement, SQL has powerful tools for extracting related data from multiple tables. Typically unique ID fields are used to create relationships. All modern database systems support automatic generation of these ID fields, and they work well for creating and managing simple or complex relationships between tables. When you need a result that includes related rows from multiple tables, you'll need to use a joined query.
It's easy to understand joins if you visualize your tables as a Venn diagram, where each of your tables are represented by intersecting shapes. The intersection of the shapes where the tables overlap, are the records where our condition is met. I.D. fields are often used for this purpose where the condition to be met is matching ID's. The simplest and most common form of a join is the inner join. This is the default and it's the join you get when you use the join key word by itself.
The result of an inner join will include rows from both tables where the joined condition is met. The inner key word is typically omitted as this is the default join. The outer join is less common, but still important to understand. A left outer join includes the rows where the condition is met, plus all the rows from the table on the left, where the condition is not met. The outer key word is typically omitted as a left join is presumed to be an outer join. Likewise, a right outer join includes all the rows from the table on the right.
This is considered a special case in many databases don't support right joins. SQL Light, the database we're using for the demonstrations in this course, does not support right joins. Generally a right join can be written as a left join by simply changing the order of the tables in the query. A full outer join includes all the rows from both tables, including those where the condition is met. Many database systems including SQLite do not implement full outer join. There are many variations of these basic joins implemented in different ways by the different database system vendors.
For most purposes you'll just need to understand these basic concepts. For more specific implementation details, you should consult the documentation for your database system.
- Understanding SQL terminology and syntax
- Creating new tables and records
- Inserting and updating data
- Writing basic SQL queries
- Sorting and filtering
- Accessing related tables with JOIN
- Working with strings
- Finding the numeric type of a value
- Using aggregate functions and transactions
- Updating a table with triggers
- Creating views
Skill Level Beginner
1. SQL Quick Start
Understanding joins2m 23s
Dates and times1m 59s
10. Subselects and Views
11. A Simple CRUD Application
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.