DBMS Lab 5 (Set Operations)
DBMS Lab 5 (Set Operations)
●
● The UNION ALL command combines the result set of two or more SELECT
statements (allows duplicate values).
(Select courseid
from section
where semester = ‘second’ and year= 2022)
union all
(Select courseid
from section
where semester = ‘first’ and year= 2023);
To compare the rows of two or more SELECT statements, the INTERSECT operator is
used. After the comparing process, the INTERSECT operator returns the common or
intersecting records from the corresponding columns of the selected expressions.
Q: To find the set of all courses taught in the in Second 2022 as well as in First 2023
(Select courseid
from section
where semester = ’Second’ and year= 2022)
intersect
(Select courseid
from section
where semester = ’First’ and year= 2023);
The except operation outputs all tuples from its first input that do not occur in
the second input; that is, it performs set difference. The operation
automatically eliminates duplicates in the inputs before performing set
difference
Q: To find all courses taught in the Second 2022 semester but not in the first
2023 semester
(Select courseid
from section
where semester = ’Second’ and year= 2022)
except
(Select courseid
from section
where semester = ’First’ and year= 2023);
Q: Find the departments where the average salary of the instructors is more than
25000.
A JOIN clause is used to combine rows from two or more tables, based on a related
column between them.
Let's look at the “Orders" and “Customers” tables:
The LEFT JOIN keyword returns all records from the left table (table1), and the
matching records from the right table (table2). The result is 0 records from the right
side, if there is no match.
Q: SELECT Customers.customername,
Orders.orderid FROM Customers
LEFT JOIN Orders ON Customers.customerid = Orders.customerid
ORDER BY Customers.customername;
– The RIGHT JOIN keyword returns all records from the right table
(table2), and the matching records from the left table (table1). The result is 0
records from the left side, if there is no match.
– The FULL OUTER JOIN keyword returns all records when there is
a match in left (table1) or right (table2) table records.