One of the columns in the article table is a foreign key to the category table.
So when we select all the columns in the query this idea is included in the results to get the name
of the category in the same resultset.
We can use a join the query.
A select query specifies the columns and the table like this we can join this to another table by using
the join key word followed by the name of the table were joining two.
If we run this query on the database joining the article and category tables the resultset contains
the product of both tables each row from the first table is matched to each row of the second table.
This isn't very useful so we need to add a condition to this query using a where clase.
We can specify in the WHERE clause that the two related columns the primary key and foreign key should
match.
When working with more than one table in a single query you can prefix the column name with the table
name followed by a dot.
Ah.
Period.
So it's clear which table the column is coming from.
So if we add a square class to the query that matches the category idees field in the article table.
So the idea field in the category table when we run this query the resultset contains the columns from
the article table and also all the columns from the category table.
We only get two records because these are the only Ricardos where the where class is true.
All the other records in the article table have the category idae set to NULL which doesn't match any
Ricardos in the category table.
The join condition can also be specified using the on keyword.
So instead of the join condition being in the WHERE clause we specify it using on.
Where conditions can still be added to a query like this.
But using on separates the join condition from the other where conditions.
So if we use on instead of putting the condition in the WHERE clause we get the same results.
We still only get the articles that have categories.
In other words those records where the category idea field isn't NULL.
This is known as a fall.
Join are a full outer join.
To get all the records from the first table.
Even if the value in the second table is null we use a left join our way left out join left jannine
and left out to join the same.
The outer key word is optional.
So if we change this join to a left join.
All of the article records are returned including those that don't have a category where the category
idae field is null.
There's an excellent article on this site here which has a visual representations of how the various
joins work including a right to join which as you might expect works the opposite way around to the
left join.