Joins in MySQL




Hello and welcome everyone. In this article, we will learn about the Joins and its type with example. Let’s go.
What is the Join?
The MySQL Joins is used to retrieving data or records from two or more table’s records or data. A table is having Primary Key and Foreign Keys and it’s used with SELECT, UPDATE, DELETE statement.

MongoDB with .Net Core course link => https://www.udemy.com/mongodb-with-net-core-sagar-jaybhay/

Web API 2- .Net Core In depth In 5 Hours click on: https://www.udemy.com/web-api-2-net-core-in-depth-in-5-hrs-with-sagar-jaybhay/

Why use Join?
In MySQL database, you can get the result of one by one using queries for a different table, but joins get the result from only one query. Joins result get better performance. Joins combine data or records from two or more table and it also returns result where the condition is satisfied.

Following are the different six types of Joins that provide MySQL:
          Inner Join
          Cross Join
          Left Join
          Right Join
          Full Join
         

Inner Join
          The inner join used to get records or data from both tables. Means inner join returns matched records from both tables.
          Syntax of Inner Join:
                   SELECT column_name_1, column_name_2, . . .
                   FROM table_name_1
                   INNER JOIN table_name_2
                   ON table_name_1.column_name = table_name_2.column_name;


Cross Join
          The Cross join matches each row from one table to another table all rows. Table one each row groupings with table second all records.
          Syntax of Cross Join:
                   SELECT column_name_1, column_name_2, . . .
FROM table_name_1
CROSS JOIN table_name_2;

  
Left Join
          The Left join is similar to an inner join. It returns all records or rows from the left side table and matching records or rows from the right side table where the join condition is satisfied. If the right side table has no matching records then right side column returns NULL values.
          The syntax for Left Join
                   SELECT column_name_1, column_name_2, . . .
                   FROM table_name_1
                   LEFT JOIN table_name_2
                   ON table_name_1.column_name = table_name_2.column_name;

Right Join
          The Right join is reverse of Left join. It returns all records or rows from the right side table and matching records or rows from the left side table where the join condition is satisfied. If the left side table has no matching record then left side columns to return NULL values.
          The syntax for Right Join
                   SELECT column_name_1, column_name_2, . . .
                   FROM table_name_1
                   RIGHT JOIN table_name_2
                   ON table_name_1.column_name = table_name_2.column_name;

  
Full Join
          The Full join it returns records or rows that matched both the right side table and left side table. Full join return very large records or rows data in result sets.
          Syntax for Full Join:
                   SELECT column_name_1, column_name_2, . . .
                   FROM table_name_1
                   FULL JOIN table_name_2
                   ON table_name_1.column_name = tbale_name_2.column_name
                   WHERE ( condition );
                  
In this article, we learned about MySQL Joins and join types.



Comments

Popular posts from this blog

ALTER statement in MySQL

Order By Clause in MySQL

MySQL Constraint – UNIQUE