Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases

For INNER JOIN, do you always get the same query result if you switch the two tables in the query?

I figured that two query statements produce the same results:

SELECT mk.MakeName, md.ModelName FROM make AS mk INNER JOIN model AS md ON mk.MakeID = md.MakeID;

SELECT mk.MakeName, md.ModelName FROM model AS md INNER JOIN make AS mk ON mk.MakeID = md.MakeID;

Is it always the case for INNER JOIN? Is there any rule or a common practice on which table you should start querying when you use INNER JOIN?

1 Answer

Steven Parker
Steven Parker
231,271 Points

You're right, it makes no difference in which order the tables are used. An INNER JOIN is a symmetric operation.

I don't know if there's any official convention, but I would generally start with the table that the first item in the SELECT comes from. So in this case, I would use your first example.