SQL Joins: SQL Joins are used to combine rows from two or more tables based on a
related column between them. They allow you to retrieve data from multiple tables
in a single query
Example of INNER JOIN
The INNER JOIN keyword selects records that have matching values in both tables.
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
This query retrieves orders along with the customer names for those orders
Types of SQL Joins
1. INNER JOIN
Returns records that have matching values in both tables.
2. LEFT (OUTER) JOIN
Returns all records from the left table, and the matched records from the right
table. If no match is found, NULL values are returned for columns from the right
table.
SELECT Student.NAME, StudentCourse.COURSE_ID
FROM Student
LEFT JOIN StudentCourse ON StudentCourse.ROLL_NO = Student.ROLL_NO;
3. RIGHT (OUTER) JOIN
Returns all records from the right table, and the matched records from the left
table. If no match is found, NULL values are returned for columns from the left
table.
SELECT Student.NAME, StudentCourse.COURSE_ID
FROM Student
RIGHT JOIN StudentCourse ON StudentCourse.ROLL_NO = Student.ROLL_NO;
4. FULL (OUTER) JOIN
Returns all records when there is a match in either left or right table. If no
match is found, NULL values are returned for columns from either table.
SELECT Student.NAME, StudentCourse.COURSE_ID
FROM Student
FULL JOIN StudentCourse ON StudentCourse.ROLL_NO = Student.ROLL_NO;
Note: The choice of join type depends on the specific requirements of your query