-
SQL Installing SSMS
-
SQL Syntax
-
SQL Datatype
-
SQL Database
-
SQL Table
-
SQL Select
-
SQL Distinct
-
SQL Count
-
SQL Top
-
SQL Aliases
-
SQL In
-
SQL Insert
-
SQL Update
-
SQL Null
-
SQL Like
-
SQL Wildcards
-
SQL Nested Query
-
SQL Between
-
SQL Unique
-
SQL Primary Key
-
SQL Foreign Key
-
SQL Check
-
SQL Default
-
SQL Database Diagram
-
SQL Stored Procedures
-
SQL Joins
-
SQL Inner Join
-
SQL Left Join
-
SQL Right Join
-
SQL Full Join
-
SQL Trigger
SQL Right Join
Join operation in SQL is used to combine multiple tables together into a single table. If we use the right join to combine two different tables, then we will get all the records from the right table. But we will get only those records from the left table, which have the corresponding key in the right table. Rest other records in the left table for which the common column value doesn’t match with the common column value of the right table; displayed as NULL.
Syntax:
SELECT TableName1.columnName1, TableName2.columnName2 FROM TableName1 RIGHT JOIN TableName2 ON TableName1.ColumnName = TableName2.ColumnName;
Table 1: Loan
Table 2: Borrower
Example
Write a query to perform the right join operation considering the loan table as the left table and the borrower table as the right table.
SELECT l.LoanID, l.Branch, l.Amount, b.CustID, b.CustName FROM Loan l RIGHT JOIN Borrower b ON l.LoanID = b.LoanID;
You will get the following output:
LoanID, Branch, Amount, CustID, CustName are retrieved from loan and borrower tables. All the records from the borrower table are retrieved. Only those records that have a corresponding LoanID in the borrower table are retrieved from the loan table. Rest other records in the loan table for which a LoanID doesn’t match with the LoanID of the borrower table, are displayed as NULL.
Course Video
1. Write a SQL query to get all productCategoryId, CategoryNamw with Product SubcategoryId, name from Production.ProductSubcategory and Production.ProductCategory.
NOTE: OUTPUT on SQL Editor Count: 37 Rows.
OUTPUT
2. Write a SQL query to get all employeeID, Job title WITH firstName, LastName, startDate from Person, HumanResources.Employee and HumanResources.EmployeeDepartmentHistory tables.
NOTE: OUTPUT on SQL Editor Count: 100 Rows.
OUTPUT
3. Write a query to join salesOrderHeader, SalesOrderDetail, SpecialOfferproduct and SpecialOffer table to retrieve two columns from each table.
NOTE: OUTPUT on SQL Server Count: 5579 Rows,
OUTPUT on SQL Editor Count: 170 Rows.
OUTPUT
4. write a SQL query to get all PurchaseOrderHeader details with ShipMethods Name, ShipRate.
NOTE: OUTPUT on SQL Editor Count: 100 Rows.
OUTPUT
5. write a SQL query to join PurchaseOrderDetail, PurchaseOrderHeader, ShipMethod table to retrieve two columns from each table.
NOTE: OUTPUT on SQL Editor Count: 156 Rows.
OUTPUT
YouTube Reference:
1) SQL Right in Hindi/Urdu
2) SQL Right in English