WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL RIGHT JOIN Keyword


SQL RIGHT JOIN Keyword

The RIGHT JOIN keyword returns all rows from the right table (demo2), with the matching rows in the left table (demo1). .

SQL RIGHT JOIN Syntax

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

or:

SELECT column_name(s)
FROM demo1
RIGHT OUTER JOIN demo2
ON demo1.column_name=demo2.column_name;

Database

In this tutorial we will use the database.

Below is a selection from the "Orders" table:

OrderID CustomerID EmployeeID OrderDate ShipperID
501 5 11 July 21, 1985 3
502 6 12 May 25, 1992 1
503 7 13 November 12, 1952 2

And a selection from the "Employees" table:

EmployeeID Name username BirthDate Password
1 Irma R. Masters Hicand February 5, 1989 mahFah8eij
2 Michael A. Gainer Tworesece March 30, 1985 TransportationMart58
3 Raymond J. Gribble Difistrunde November 1, 1975

SQL RIGHT JOIN Example

The following SQL statement will return all employees, and any orders they have placed:

Example

SELECT Orders.OrderID, Employees.FirstName
FROM Orders
RIGHT JOIN Employees
ON Orders.EmployeeID=Employees.EmployeeID
ORDER BY Orders.OrderID;