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 - RIGHT JOIN

The SQL right join returns all the values from the rows of right table.

It also includes the matched values from left table but if there is no matching in both tables, it returns NULL.


Syntax : RIGHT JOIN


SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name; 

join

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


Table : Students

ROLL_NO STU_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 TECH_NAME SUBJECT ROLL_NO
20 Kayla PHP 6
21 Albert Java 4
21 Albert Java 5
22 Helen Node.js 3
23 Anne Python 2
24 Jaime C++ 1


The following MySQL statement will return all Teachers, and Students they might have placed:


Example : RIGHT JOIN



SELECT Students.ROLL_NO,Teachers.TECH_NO, , Teachers.NAME
FROM Students
RIGHT JOIN Teachers ON Teachers.ROLL_NO = Students.ROLL_NO
ORDER BY Students.ROLL_NO;

Now, after executing the above SQL statement,

ROLL_NO TECH_NO TECH_NAME
1 24 Jaime
2 23 Anne
3 22 Helen
4 21 Albert
5 21 Albert
6 20 Kayla