0% found this document useful (0 votes)
4 views16 pages

2-Relational Operations

The document outlines various relational operations in data management, including SELECT, PROJECT, UNION, INTERSECT, DIFFERENCE, and PRODUCT. It explains unary operations that apply to a single relation and binary operations that involve two relations, providing examples for each operation. Additionally, it emphasizes the importance of compatibility between relations for certain operations to yield valid results.

Uploaded by

mthuramge99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views16 pages

2-Relational Operations

The document outlines various relational operations in data management, including SELECT, PROJECT, UNION, INTERSECT, DIFFERENCE, and PRODUCT. It explains unary operations that apply to a single relation and binary operations that involve two relations, providing examples for each operation. Additionally, it emphasizes the importance of compatibility between relations for certain operations to yield valid results.

Uploaded by

mthuramge99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

RELATIONAL

OPERATIONS
Data Definition Language
RELATIONAL OPERATIONS
 SELECT
 PROJECT
 UNION
 INTERSECT
 DIFFERENCE
 PRODUCT

 UNARY OPERATIONS can be applied to one relation, e.g.


SELECT and PROJECT
 BINARY OPERATIONS are applied to two relations, e.g. JOIN
SELECTION OPERATION

 Can be used to list all rows, or return only raw values


that match specified criteria
 It is possible to create more complex criteria by using
the logic operator AND, OR, NOT
SELECTION OPERATION

Student ID Name Surname


17865457 Jane Sibeko
54698699 Jane Dutton

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

StudentID StudentName StudentAccStatus


78952468 Velaphi Active
89954322 Phephelaphi Active
56677888 Vukani InActive

The projection of student name and student account status from the
student accounts table
StudentNAme StudentAccStatus
Velaphi Active
Phephelaphi Active
Vukani InActive

SELECT DISTINCT StudentName, StudentAccStatus


UNION OPERATION
 Combines all rows from two relations excluding
duplications
 The relations must have the same attribute
characteristics (i.e. the columns and domains must be
identical) to be used in the union
 When two or more relations share the same columns,
they are said to be union-compatible
 If two relations are not union-compatible, then the
UNION operator cannot be applied as results would be
invalid
UNION OPERATION
ID Name ID Name
1 Ben 2 John
2 John 3 Ryan

SELECT * FROM first_table


UNION
SELECT * FROM second_table;

ID Name
1 Ben
2 John
3 Ryan
UNION ALL OPERATION
ID Name ID Name
1 Ben 2 John
2 John 3 Ryan

SELECT * FROM first_table


UNION ALL
SELECT * FROM second_table;

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

SELECT * FROM first_table


INTERSECT
SELECT * FROM second_table;

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

SELECT * FROM first_table


MINUS
SELECT * FROM second_table;

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

SELECT * FROM first_table


CROSS JOIN
SELECT * FROM second_table;

Student_id Course_name Credit_status Student_id Department_na


me
CONCLUSION
 SELECT
 PROJECT
 UNION
 INTERSECT
 DIFFERENCE
 PRODUCT

 UNARY OPERATIONS can be applied to one relation, e.g.


SELECT and PROJECT
 BINARY OPERATIONS are applied to two relations, e.g. JOIN

You might also like