forked from vky00529/DBMS_G_23_24_25_26_27
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFull Join
38 lines (34 loc) · 2.1 KB
/
Full Join
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Full Join : - It returns all records when there is a match in either the left table or the right table. If there is no match, the result will still include the records, but with NULL values. It is also known as FULL Outer Join.
Syntax : - SELECT table1.column1,table1.column2,table2.column1,....
FROM table1
Full JOIN table2
ON table1.matching_column = table2.matching_column;
MySQL historically did not support the FULL JOIN (also known as FULL OUTER JOIN) because it was designed with simplicity and performance in mind, focusing on the most commonly used features in SQL.
Reasons
1. Demand and Use Cases:
Limited Use Cases: FULL JOIN is less commonly used compared to INNER JOIN, LEFT JOIN, and RIGHT JOIN. Most queries in practical applications can be handled with these joins, and the need for FULL JOIN is relatively rare.
MySQL’s initial design prioritized features that were most commonly needed by its user base.
2. Performance Considerations:
Complexity and Performance: Implementing FULL JOIN directly requires the database engine to process all rows from both tables and handle the matching of all rows while including NULL where there is no match. This can be computationally expensive, especially with large datasets. By not including FULL JOIN, MySQL avoids the performance overhead associated with it.
3. Focus on Simplicity:
Simplicity: MySQL was originally developed to be a lightweight and simple-to-use database management system. To keep it efficient and easier to maintain, certain advanced or less-used features like FULL JOIN were omitted from its earlier versions.
Alternatives : -
Syntax : -
SELECT table1.column1,table1.column2,table2.column1,....
FROM table1
LEFT JOIN table2
ON table1.matching_column = table2.matching_column
UNION
SELECT table1.column1,table1.column2,table2.column1,....
FROM table1
RIGHT JOIN table2
ON table1.matching_column = table2.matching_column;
Example : -
Find all the students name and all the listed courses
SELECT st.Name, st1.CourseName
FROM st
LEFT JOIN st1 ON st.CourseID = st1.CourseID
UNION
SELECT st.Name, st1.CourseName
FROM st
RIGHT JOIN st1 ON st.CourseID = st1.CourseID;