Professional Documents
Culture Documents
Final Presentation
Final Presentation
Group Members
• Combine rows from two or more tables based on a • Combine results of two or more SELECT queries.
related column.
• Require a relationship between tables, usually defined by • Do not require relationships; can combine unrelated
a foreign key. datasets.
• Can be more performance-intensive due to the need to • Can be more straightforward but may involve sorting and
match rows based on keys. removing duplicates, affecting performance.
Type Of Set Operators
Work
Operator
• The UNION set operator in SQL is used when you need to
combine the results obtained from two or more SELECT
statements.
• Important: UNION statements only return UNIQUE
values.
Note that "Harry Potter" – an item which appears in both tables – is shown only once in the results.
Like we mentioned earlier, the UNION set operator does not return duplicate values.
Union All Set Output:
Work
Operator
• UNION ALL is very similar to UNION, but with one
exception: UNION ALL returns all data from all tables, no
matter if it is a duplicate or not.
• Let's do the same operation as in the UNION example and
see what we get:
e.g: You are creating a report that requires e.g: You are consolidating transactions where
unique records from multiple tables. duplicates are meaningful and should be
preserved.
Except Set Operator
Work
Now "Harry Potter" doesn't appear in the results table; it's the title of a book and a movie. Thanks to
the MINUS set operator we are able to see only those titles that occur in the first table and are not
present in the second.
By the way, some databases use the keyword MINUS instead of EXCEPT. Don't worry – the
function and results are exactly the same.
INTERSET Set
Work
Operator
• The INTERSECT operator in SQL is used to combine the Output:
result sets of two SELECT statements and returns only the
rows that appear in both result sets.
• The SELECT lists in both queries must have the same number of columns.
• The data types of each column in the second query must match the data type of
the corresponding column in the first query.
• The ORDER BY clause can only appear at the very end of the statement, not
before a set operator or within individual SELECT statement
ORDER BY Clause
Work
• Sorting: The ORDER BY clause sorts the entire result set Output:
produced by the combined query.
• Consistency: Ensure the columns being combined have the
same data type and are named consistently across queries.