Professional Documents
Culture Documents
DBMS Practical No. - 04
DBMS Practical No. - 04
Theory:
Basically, a table could be defined as a relation, i.e. a set of elements. Thus in
relational database all the data is stored in the form of sets. A query returns a set of
rows, so you can do additional set operations on the output of a query.
Union Operation
The UNION operator is used to combine the result-set of two or more SELECT
statements.
Syntax:
Notice that each SELECT statement within the UNION must have the same number
of columns. The columns must also have similar data types. Also, the columns in each
SELECT statement must be in the same order.
Department
Warehouseinfo
LOCID WAREHOUSENAME
---------- ----------
1400 southlake
3452 raipur
2345 bihar
Page 1 of 5
Example:-
SQL> select locid, warehousename from department
UNION
select locid, warehousename from warehouseinfo;
The UNION operator selects only distinct values by default. To allow duplicate
values, use the ALL keyword with UNION.
Syntax
Note: The column names in the result-set of a UNION are usually equal to the
column names in the first SELECT statement in the UNION.
Example:
Intersect Operation
Page 2 of 5
The SQL INTERSECT operator is used to return the results of 2 or more SELECT
statements. However, it only returns the rows selected by all queries. If a record exists
in one query and not in the other, it will be omitted from the INTERSECT results.
Each SQL statement within the SQL INTERSECT must have the same number of
fields in the result sets with similar data types.
Syntax
Example:
SQL> select locid from department INTERSECT select locid from warehouseinfo;
Result: - LOCID
----------
1400
MINUS Operation:
The SQL MINUS operator is used to return all rows in the first SELECT statement
that are not returned in the second SELECT statement.
Each SELECT statement within the MINUS query must have the same number of
fields in the result sets with similar data types.
Syntax
Example:-
SQL> select locid, warehousename from department MINUS select locid,
warehousename from warehouseinfo;
Page 3 of 5
Lab Exercise for Practical No. 4
1. List all the customers who are depositors but not borrowers
2. List all the customers who are both depositors and borrowers
3. List all the customers, along with their amount, who are either borrowers or
depositors and living in city NAGPUR
Page 4 of 5
Page 5 of 5