JOINs
JOINs
The whole purpose of JOIN statements is to allow us to pull data from more than one table at a time.
Again - JOINs are useful for allowing us to pull data from multiple tables. This is both simple and powerful all at the same time.
With the addition of the JOIN statement to our toolkit, we will also be adding the ON statement.
We use ON clause to specify a JOIN condition which is a logical statement to combine the table in FROM
and JOIN
statements.
Write Your First JOIN
Below we see an example of a query using a JOIN statement. Let's discuss what the different clauses of this query mean.
SELECT orders.* FROM orders JOIN accounts ON orders.account_id = accounts.id;
As we've learned, the SELECT clause indicates which column(s) of data you'd like to see in the output (For Example, orders. gives us all the columns in orders table in the output). The FROM clause indicates the first table from which we're pulling data, and the JOIN indicates the second table. The ON* clause specifies the column on which you'd like to merge the two tables together.
Comments
Post a Comment