close[x]


MySQL

MySQL-Home MySQL-Environment setup MySQL- Workbench MySQL-Basic syntax MySQL-Operator MySQL-Data type MySQL-Comments MySQL-Create DB MySQL-Drop DB MySQL-Select DB MySQL-Create Table MySQL-Drop table MySQL-Truncate MySQL-Primary Key MySQL-Foreign Key MySQL-Null MySQL-Increment MySQL-Having MySQL-Top MySQL-Insert Statement MySQL-Select Statement MySQL-Alter Statement MySQL-Where MySQL-And & Or MySQL-Default values MySQL-Exists MySQL-Order by MySQL-View MySQL-Update Statement MySQL-Delete Statement MySQL-Like MySQL-Sort MySQL-Limit MySQL-Min MySQL-Max MySQL-Group MySQL-In MySQL-Between MySQL-Union MySQL-Count MySQL-Average MySQL-Sum MySQL-Date & Time MySQL-Import MySQL-Export MySQL-Index MySQL-Temporary MySQL-Join MySQL-Full Join MySQL-Inner Join MySQL-Left Join MySQL-Right Join MySQL-Store Procedure MySQL-Injection MySQL-PHP connection



learncodehere.com




MySQL - JOIN

JOIN means "to combine two or more tables".

A JOIN clause is used to combine rows from two or more tables, based on a related column between them

We've a table named Students and Teachers in our database that contains the following records:


Table : Students

ROLL_NO NAME SUBJECT
1 Will C++
2 SAM Python
3 Rani Node.js
4 Rim Java
5 Micheal JAVA
6 Lara PHP

Table : Teachers

TECH_NO NAME SUBJECT ROLL_NO
20 Kayla PHP 6
21 Albert Java 2
21 Albert Java 5
22 Helen Node.js 3
23 Anne Python 2
24 Jaime C++ 1

Notice that the "ROLL_NO" column in the "Teachers" table refers to the "ROLL_NO" in the "Students" table. The relationship between the two tables above is the "ROLL_NO" column.

We can make different type of Join statement with this kind of relations in a table.



Types of MySQL JOINs

  • (INNER) JOIN : A join that returns only those rows that have a match in both joined tables
  • LEFT (OUTER) JOIN : Returns all records from the left table, and the matched records from the right table
  • RIGHT (OUTER) JOIN : Returns all records from the right table, and the matched records from the left table
  • FULL (OUTER) JOIN : Returns all records when there is a match in either left or right table

  • join