We’ve now written several JOIN queries. Before moving forward, there are some very important things you need to understand about JOIN syntax. These small details will save you fr
MSMuhammad SufiyanSoftware Engineer · 5d ago
Backend Engineering HubT-
We’ve now written several JOIN queries.
Before moving forward, there are some very important things you need to understand about JOIN syntax.
These small details will save you from confusion later — especially when queries become complex.
Let’s go step by step.
1️⃣ Does Table Order Matter in JOIN?
Sometimes yes. Sometimes no.
Consider this query:
SELECT *
FROM comments
JOIN photos
ON photos.id = comments.photo_id;
Now flip it:
SELECT *
FROM photos
JOIN comments
ON photos.id = comments.photo_id;
In many cases, you’ll get the same result.
But in some cases (especially when we talk about LEFT JOIN and RIGHT JOIN), the order will change the result.
For now, remember this:
Table order sometimes matters — and later, we’ll see exactly when.
2️⃣ Ambiguous Column Names
This is one of the most common beginner mistakes.
Let’s imagine we join comments and photos.
Both tables have a column named:
id
After the JOIN, our temporary result table looks like:
id
contents
photo_id
id
url
Now if we write:
SELECT id
FROM comments
JOIN photos
ON photos.id = comments.photo_id;