Tables aliases
Let’s look at our very first query with join:
SELECT * FROM purchases INNER JOIN users ON purchases.user_id = users.id
Firstly, in the JOIN
condition we specified which table we’re joining – users
.
SQL engine will scan every row in the purchases
table and determine whether we need to join some rows from the users
table to it or not. For that, we need to specify a condition for joining. It always starts with the ON keyword: ON purchases.user_id = users.id
.
Since some columns might have the same names in both tables we need to...