0% found this document useful (0 votes)
6 views7 pages

Set Operators in MySQL

Set operators in MySQL are used to combine results from multiple SELECT queries, with key operators including UNION, UNION ALL, INTERSECT, and EXCEPT. UNION removes duplicates while UNION ALL retains them, INTERSECT finds common rows, and EXCEPT returns rows from the first query not present in the second. It's important to follow rules regarding the number of columns and data types for successful query execution.

Uploaded by

rawshmic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views7 pages

Set Operators in MySQL

Set operators in MySQL are used to combine results from multiple SELECT queries, with key operators including UNION, UNION ALL, INTERSECT, and EXCEPT. UNION removes duplicates while UNION ALL retains them, INTERSECT finds common rows, and EXCEPT returns rows from the first query not present in the second. It's important to follow rules regarding the number of columns and data types for successful query execution.

Uploaded by

rawshmic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Set Operators in MySQL

Combining Results from Multiple


Queries
Introduction to Set Operators
• • Definition: Used to combine results from
two or more SELECT queries.
• • Key Operators:
• - UNION
• - UNION ALL
• - INTERSECT (if supported)
• - EXCEPT / MINUS
UNION and UNION ALL
• • UNION: Combines results and removes
duplicates.
• • UNION ALL: Combines results without
removing duplicates.
• Example:
• SELECT name FROM students;
• UNION
• SELECT name FROM teachers;
INTERSECT (If Supported)
• • Returns rows that are common in both
queries.
• Example:
• SELECT id FROM orders;
• INTERSECT
• SELECT id FROM delivered_orders;
EXCEPT / MINUS
• • EXCEPT: Returns rows from the first query
not in the second.
• Example:
• SELECT id FROM orders;
• EXCEPT
• SELECT id FROM delivered_orders;
Rules for Set Operators
• • Same number of columns in queries.
• • Columns must have compatible data types.
• • ORDER BY is applied to the final result.
Conclusion
• • Effective for merging datasets.
• • Keep syntax rules in mind.
• • Enhances query flexibility and power.

You might also like