Here we see all of our users and their addresses in one nice result set.īesides producing a combined result set, another important use of joins is to pull extra information into our query that we can filter against.įor example, if we wanted to send some physical mail to all users who live in Oklahoma City, we could use this joined-together result set and filter based on the city column. We'll look at how to write these joins soon, but if we joined our user information to our address information we could get a result like this: id | name | email | age | id | street | city | state | user_id We could write separate queries to retrieve both the user information and the address information-but ideally we could write one query and receive all of the users and their addresses in the same result set. +-+-+-+-ġ | 1234 Main Street | Oklahoma City | OK | 1Ģ | 4444 Broadway Ave | Oklahoma City | OK | 2 +-+-+-Īnd the rows from the table that stores address information might look like this: id | street | city | state | user_id The rows from the table that stores user information might look like this: id | name | email | age Let's take for example a system that stores information about users and their addresses. These rows are usually from two different tables-but they don't have to be.īefore we look at how to write the join itself, let's look at what the result of a join would look like. ( Spoiler alert: we'll cover five different types-but you really only need to know two of them!) What is a join?Ī join is an operation that combines two rows together into one row. The reality about writing queries with joins. Setting up our example data (directors and movies).In this article, we'll look at each of the different join types in SQL and how to use them. Joins allow us to re-construct our separated database tables back into the relationships that power our applications. SQL joins allow our relational database management systems to be, well, relational.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |