"if you encounter any errors in SAP, send me a screenshot at pramod@learntosap.com, and I will help you resolve the issue."

SQL Joins, SQL Inner Join, SQL Left Join, SQL Right Join, SQL Full Join

SQL TUTORIALS-

SQL Joins

Introduction-


Trulli Trulli

SQL Joins, SQL Inner Join, SQL Left Join, SQL Right Join, SQL Full Join, SQL join examples

βœ…Simple Joins are used in SQL to combine rows from two or more tables based on a related column..

Emoji Examples in HTML

πŸ”Έ Types of SQL JOINS:

Join Type Description
INNER JOIN Please Note- Returns only matching rows from both tables.
LEFT JOIN Please Note- Returns all rows from the left table and matching rows from the right.
RIGHT JOIN Please Note- Returns all rows from the right table and matching rows from the left.
FULL OUTER JOIN Please Note- Returns all rows when there is a match in one of the tables.
CROSS JOIN Please Note- Returns cartesian product (every row of table A with every row of table B).

πŸ’‘ Note: The SQL JOINS Table. Example Of Two Tables- 1-)Employee and 2-)Department.
Emoji Examples in HTML

πŸ”Έ Example 1-)Table: Employee


EmpID EmpName DeptID
1 ANNI 1001
2 SUJAN 1002
3 BOULT 1003
4 POOJA NULL
Emoji Examples in HTML

πŸ”Έ Example 2-)Table: Department


EmpID DeptName
1001 IT
1002 HR
1003 Finance
1004 Production

βœ… Example 1: INNER JOIN – Matching records in both tables-



SELECT Employee.EmpName, Department.DeptName
FROM Employee
INNER JOIN Department ON Employee.DeptID = Department.DeptID;

βœ…Result Show :-

Result β†’

Emoji Examples in HTML


EmpName DeptName
ANNI IT
SUJAN HR
BOULT Finance

βœ… Example 2: LEFT JOIN – All employees, with their department if available-



SELECT Employee.EmpName, Department.DeptName
FROM Employee
LEFT JOIN Department ON Employee.DeptID = Department.DeptID;

βœ…Result Show :-

Result β†’

Emoji Examples in HTML


EmpName DeptName
ANNI IT
SUJAN HR
BOULT Finance
POOJA NULL

πŸ’‘ Note: The SQL JOINS is used in SQL to combine rows from two or more tables based on a related column (usually a foreign key).

βœ… Example 3: RIGHT JOIN – All departments, if no employee assigned-



SELECT Employee.EmpName, Department.DeptName
FROM Employee
RIGHT JOIN Department ON Employee.DeptID = Department.DeptID;


βœ…Result Show :-

Result β†’

Emoji Examples in HTML


EmpName DeptName
ANNI IT
SUJAN HR
BOULT Finance
NULL Production

βœ… Example 4. FULL OUTER JOIN – All employees and all departments-



SELECT Employee.EmpName, Department.DeptName
FROM Employee
FULL OUTER JOIN Department ON Employee.DeptID = Department.DeptID;

βœ…Result Show :-

Result β†’

Emoji Examples in HTML


EmpName DeptName
ANNI IT
SUJAN HR
BOULT Finance
NULL Production
POOJA NULL

Practice - Yes/No Quiz

1.Can a LEFT JOIN return NULL values if there's no match in the right table?

2.Does an INNER JOIN return unmatched rows from either table?

3.Is it true that a FULL OUTER JOIN shows only matched rows from both tables?


May Be Like Important Link-

-SQL Tutorial for Beginners – Introduction to SQL

-SQL TOP, LIMIT, FETCH FIRST or ROWNUM Clause

-SQL SELECT DISTINCT Statement Clause Explained with Examples

-SQL Wildcard Characters: Complete Guide with Examples