

Create a join in idatabase how to#
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.
