C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
SQL Set OperationThe SQL Set operation is used to combine the two or more SQL SELECT statements. Types of Set Operation
1. Union
Syntax SELECT column_name FROM table1 UNION SELECT column_name FROM table2; Example: The First table
The Second table
Union SQL query will be: SELECT * FROM First UNION SELECT * FROM Second; The resultset table will look like:
2. Union AllUnion All operation is equal to the Union operation. It returns the set without removing duplication and sorting the data. Syntax: SELECT column_name FROM table1 UNION ALL SELECT column_name FROM table2; Example: Using the above First and Second table. Union All query will be like: SELECT * FROM First UNION ALL SELECT * FROM Second; The resultset table will look like:
3. Intersect
Syntax SELECT column_name FROM table1 INTERSECT SELECT column_name FROM table2; Example: Using the above First and Second table. Intersect query will be: SELECT * FROM First INTERSECT SELECT * FROM Second; The resultset table will look like:
4. Minus
Syntax: SELECT column_name FROM table1 MINUS SELECT column_name FROM table2; Example Using the above First and Second table. Minus query will be: SELECT * FROM First MINUS SELECT * FROM Second; The resultset table will look like:
Next TopicDBMS SQL Cursors
|