MySQL Joins, MySQL INNER, LEFT, RIGHT Joins For Beginners

Today, We want to share with you mysql joins.In this post we will show you MySQL Join Tutorial: Inner, Outer, Cross, Left, Right And Self, hear for PHP MySQL Joins Tutorial we will give you demo and example for implement.In this post, we will learn about SQL Left Outer Join with an example.

SQL | Join (Inner, Left, Right and Full Joins)

Here are the different types of the JOINs in SQL:

  • INNER JOIN: Returns records that have matching values in both tables
  • LEFT JOIN: Returns all records from the left table, and the matched records from the right table
  • RIGHT JOIN: Returns all records from the right table, and the matched records from the left table
  • FULL JOIN: Returns all records when there is a match in either left or right table
  • CROSS JOIN: This join produces a result where the number of rows in the first table gets multiplied with the rows in the second table.
  • SELF JOIN: Self-join is a regular join and here the table joins with itself only.

INNER JOIN MySQL

Example 1:

SELECT city, country
 FROM city
 INNER JOIN country ON
 city.country_id = country.country_id;

LEFT JOIN MySQL

Example 2:

SELECT 
     u.member_id, 
     u.profilenm, 
     u.sirname,
     a.autor_id,
     a.profilenm,
     a.sirname
 FROM members u
 LEFT JOIN actor a 
 ON u.sirname = a.sirname
 ORDER BY u.sirname;

Right JOIN MySQL

Example 3:

SELECT 
     u.member_id, 
     u.profilenm, 
     u.sirname,
     a.autor_id,
     a.profilenm,
     a.sirname
 FROM members u
 RIGHT JOIN actor a 
 ON u.sirname = a.sirname
 ORDER BY a.sirname;

Self Join MySQL

Example 4:

SELECT 
     a.customer_id, 
     a.profilenm, 
     a.sirname, 
     b.customer_id,
     b.profilenm, 
     b.sirname 
 FROM customer a
 INNER JOIN customer b
 ON a.sirname = b.profilenm;

Cross Join MySQL

SELECT c.profilenm, c.sirname, company.name
FROM customer c
CROSS JOIN company;

I hope you get an idea about mysql joins with example..
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment