MySQL JOIN Clauses (2/4) – The Inner JOIN
In this short article series I would like to describe the meaning of MySQL Join clauses. MySQL semantics is similar among different SQL database engines, so this knowledge could be proudly used in other SQL environments. Have a nice reading in part two of four.
Here, in the previous article, you can read about the Cross JOIN Clause. Now, let’s focus on the Inner JOIN.
Inner JOIN
The Inner JOIN is typically used to return selected rows from both tables when satisfy a specific condition. Imagine that you want to get a list of members who have rented movies together with titles of movies rented by them. To do this, you can just is an Inner JOIN, which returns rows from both tables that reach given condition:
SELECT members.`first_name`, members.`last_name`, movies.`title` FROM members, movies WHERE movies.`id`=members.`movie_id`
Executing the above query, we should see the following result:
Note that we can reach the same results using other SQL semantics as well:
SELECT A.`first_name`, A.`last_name`, B.`title` FROM `members` as A INNER JOIN `movies` as B ON B.`id`=A.`movie_id`
Also visit the third article where you can read about the Outer JOINs.