JOIN
tables we can think of it as temporarily creating a new table matching rows as the condition defines.JOIN
to display comments and the url for the associated photo:FROM
and JOIN
will usually many a difference.
column reference "id" is ambiguous
.
before the column name:
AS
keyword.
AS
keyword all together:
AS
for clarity.null
value in the user_id field will be shown.null
value does not meet the ON
condition.Up to this point we have be using an ‘Inner Join’
Types of JOINS:
JOIN
or INNER JOIN
can be used interchangeably.FROM
table and the JOIN
table will make a difference when doing a LEFT
or RIGHT
OUTER JOIN
.WHERE
to a JOIN
statement to filter out results.WHERE
will always come after the JOIN
clause.WHERE
used to filter all comments to only show comments made by the user who posted the photo.JOIN
statements to include more tables.When we begin adding more joins, we need to be even more aware of our ON
condition.