The document explains set operators used in SQL to combine results from multiple SELECT statements. It details four operators: UNION (removes duplicates), UNION ALL (keeps duplicates), INTERSECT (returns common results), and EXCEPT (returns results in the first set but not in the second). Each operator is accompanied by a description and an example for clarity.
The document explains set operators used in SQL to combine results from multiple SELECT statements. It details four operators: UNION (removes duplicates), UNION ALL (keeps duplicates), INTERSECT (returns common results), and EXCEPT (returns results in the first set but not in the second). Each operator is accompanied by a description and an example for clarity.
Course created by Satish Dhawale | www.skillcourse.in
Combine the results of two or more SELECT statements
Operator Description
UNION Combines results, removes duplicates
UNION ALL Combines results, keeps duplicates
INTERSECT Returns common results
EXCEPT Returns results in first, not second
Combine the results of two or more SELECT statements
Operator Description Example Result
SELECT student_name, course FROM
students_2023 Combines results, removes UNION UNION Unique combined results duplicates SELECT student_name, course FROM students_2024; SELECT student_name, course FROM students_2023 UNION ALL Combines results, keeps duplicates UNION ALL All combined results SELECT student_name, course FROM students_2024; SELECT student_name, course FROM students_2023 INTERSECT Returns common results INTERSECT Common results only SELECT student_name, course FROM students_2024; SELECT student_name, course FROM students_2023 EXCEPT Returns results in first, not second EXCEPT Results only in first SELECT student_name, course FROM students_2024;