2-Relational Operations
2-Relational Operations
OPERATIONS
Data Definition Language
RELATIONAL OPERATIONS
SELECT
PROJECT
UNION
INTERSECT
DIFFERENCE
PRODUCT
Select all students from the student_profiles table whose name is Jane
SELECT Name
FROM student_profiles
WHERE Name = ‘Jane’;
PROJECTION
The project operator returns all values for
selected attributes
It returns a vertical subset of a relation
excluding any duplicates
Projection means choosing which columns the
query shall return
The projection is obtained by adding the word
DISTINCT
PROJECTION OPERATION
The projection of student name and student account status from the
student accounts table
StudentNAme StudentAccStatus
Velaphi Active
Phephelaphi Active
Vukani InActive
ID Name
1 Ben
2 John
3 Ryan
UNION ALL OPERATION
ID Name ID Name
1 Ben 2 John
2 John 3 Ryan
ID Name
1 Ben
2 John
2 John
3 Ryan
INTERSECT OPERATION
The INTERSECT operator returns only those
rows that appear in both relations
The relations must be UNION-COMPATIBLE to
give valid results
For example, you cannot use the INTERSECT
operator if the attribute in the first table is
numeric and in the second table is character
INTERSECT OPERATION
ID Name ID Name
1 Ben 2 John
2 John 3 Ryan
ID Name
2 John
DIFFERENCE OPERATION
The DIFFERENCE operator returns all rows in
one relation that are not found in the other
table
It subtracts one relation from the other
The DIFFERENCE operator requires that two
relations must be union -compatible
DIFFERENCE OPERATION
ID Name ID Name
1 Ben 2 John
2 John 3 Ryan
ID Name
1 Ben
PRODUCT OPERATION
The CARTESIAN PRODUCT or simply PRODUCT
contains all attributes which are present in
two relations with possible combinations of
rows from both the relations
For example, if one relation has six rows and
four attributes and the other has three rows
and two attributes, the PRODUCT creates a
new relation compound of 18 (6 X3) rows and
6 (4+2) attributes
PRODUCT OPERATION
Student_id Course_nam Credit- Student_id Department_nam
e status e