You are on page 1of 81

Unit-3

Relational Query
Languages
Structure of
Relational Databases
Student Table
Columns (5)

Attributes:
RollNo Name Branch Semester SPI
Title of column
101 Raju CE 3 8

Cardinality = No of tuples (7)


102 Mitesh CI 3 7
Rows or 103 Mayur CE 3 6
Tuples or
Records (7) 104 Nilesh EE 3 9
105 Hitesh CI 3 7
106 Tarun ME 3 8
107 Suresh CE 3 9

Degree = No of columns (5)

• Domain is a set of all possible unique values for a specific column.


• Domain of Branch attribute is (CE, CI, ME, EE)
Structure of relational databases
 Table (Relation): A database object that holds a
collection of data for a specific topic. Table consist of
rows and columns.
 Column (Attribute): The vertical component of a
table. A column has a name and a particular data type;
e.g. varchar, decimal, integer, datetime etc.
 Record (Tuple): The horizontal component of a table,
consisting of a sequence of values, one for each
column of the table. It is also known as row.
 A database consists of a collection of tables
(relations), each having a unique name.
KEYS
Super Key
 A super key is a set of one or more attributes whose
values uniquely identifies each record within a
relation (table).

Super Key Super Key Super Key


EnrollNo (RollNo, Branch, Sem) (SPI, Name, BL)

EnrollNo RollNo Branch Sem SPI Name BL


191230107001 101 CE 3 8 Jatin 0
191230107002 102 CE 3 7 Meet 0
191230106001 101 CI 3 8 Ram 0
191230106002 102 CI 3 6 Jatin 1
Candidate Key
 A candidate key is a subset of a super key.
 A candidate key is a single attribute or the least combination
of attributes that uniquely identifies each record in the table.
 A candidate key is a super key for which no proper subset is a
super key.
 Every candidate key is a super key but every super key is
not a candidate key.
Candidate Key Candidate Key
EnrollNo (RollNo, Branch, Sem)

EnrollNo RollNo Branch Sem SPI Name BL


191230107001 101 CE 3 8 Jatin 0
191230107002 102 CE 3 7 Meet 0
191230106001 101 CI 3 8 Ram 0
191230106002 102 CI 3 6 Jatin 1
Primary Key
 A primary key is a candidate key that is chosen by database
designer to identify tuples uniquely in a relation (table).

Primary Primary
Key Key

Candidate Key Candidate Key


EnrollNo (RollNo, Branch, Sem)

EnrollNo RollNo Branch Sem SPI Name BL


191230107001 101 CE 3 8 Jatin 0
191230107002 102 CE 3 7 Meet 0
191230106001 101 CI 3 8 Ram 0
191230106002 102 CI 3 6 Jatin 1
Alternate Key
 An alternate key is a candidate key that is not chosen by
database designer to identify tuples uniquely in a relation.

Primary Key Alternate Key

Candidate Key Candidate Key


EnrollNo (RollNo, Branch, Sem)

EnrollNo RollNo Branch Sem SPI Name BL


191230107001 101 CE 3 8 Jatin 0
191230107002 102 CE 3 7 Meet 0
191230106001 101 CI 3 8 Ram 0
191230106002 102 CI 3 6 Jatin 1
Primary Key rules
 A primary key may have one or more attributes.
 There is only one primary key in the relation (table).
 A primary key attribute value cannot be null.
 Generally, the value of a primary key attribute does not change.
Foreign Key
 A foreign key is used to link two relations (tables).
 A foreign key is an attribute or collection of attributes in one
table that refers to the primary key in another table.
 A table containing the foreign key is called the child table, and
the table containing the primary key is called the parent table.

Parent Child
Table Table

Student Project
EnrollNo Name Branch Sem ProjectID Title EnrollNo
170540107001 Jatin CE 3 P01 Bank 170540107001
170540107002 Meet CE 3 P02 College 170540107002
170540107003 Ram CE 3 P03 School 170540107002
Relational Algebra
Operations
Basic Relational Algebra Operations
Operator
Selection Display particular rows/records/tuples from a relation
Projection Display particular columns from a relation
Cross Product Multiply each tuples of both relations
Division Divides one relation by another
Rename Rename a column or a table
Joins Combine data or records from two or more tables
1. Natural Join / Iner Join
2. Outer Join
1. Left Outer Join 2. Right Outer Join 3. Full Outer Join

Set Operators Combine the results of two queries into a single result
1. Union 2. Intersection 3. Minus / Set-difference
Relational Algebra
Operations
Selection Operator
Selection Operator
 Symbol:  (Sigma)
 Notation:  condition (Relation)
 Operation: Selects tuples from a relation that satisfy a given
condition.
 Operators: =, <>, <, >, <=, >=, Λ (AND), V (OR)
Selection Operator example [ ]
condition(Relation)

 Display the detail of students belongs to “CE” branch.

Student
RollNo Name Branch SPI
101 Raj CE 8
102 Meet ME 9
103 Harsh EE 8
104 Punit CE 9

 Branch=‘CE’ (Student)
Output
RollNo Name Branch SPI
101 Raj CE 8
104 Punit CE 9
Selection Operator example [ ]
condition(Relation)

 Display the detail of students belongs to “CE” branch and


having SPI more than 8.
Student
RollNo Name Branch SPI
101 Raj CE 8
102 Meet ME 9
103 Harsh EE 8
104 Punit CE 9

 Branch=‘CE’ Λ SPI>8 (Student)


Output
RollNo Name Branch SPI
104 Punit CE 9
Selection Operator example [ ]
condition(Relation)

 Display the detail of students belongs to either “EE” or “ME”


branch.
Student
RollNo Name Branch SPI
101 Raj CE 8
102 Meet ME 9
103 Harsh EE 8
104 Punit CE 9

 Branch=‘EE’ V Branch=‘ME’ (Student)


Output
RollNo Name Branch SPI
102 Meet ME 9
103 Harsh EE 8
Selection Operator example [ ]
condition(Relation)

 Display the detail of students whose SPI between 7 and 9.

Student
RollNo Name Branch SPI
101 Raj CE 8
102 Meet ME 9
103 Harsh EE 8
104 Punit CE 9

 SPI>7 Λ SPI<9 (Student)


Output
RollNo Name Branch SPI
101 Raj CE 8
103 Harshan EE 8
Relational Algebra
Operations
Projection Operator
Projection Operator
 Symbol:  (Pi)
 Notation:  attribute set (Relation)
 Operation: Selects specified attributes of a relation.
 It removes duplicate tuples (records) from the result.
Projection Operator example [ attribute set (Relation)]
 Display rollno, name and branch of all students.
Student
RollNo Name Branch SPI
101 Raj CE 8
102 Meet ME 9
103 Harsh EE 8
104 Punit CE 9

 RollNo, Name, Branch (Student)


Output
RollNo Name Branch
101 Raj CE
102 Meet ME
103 Harsh EE
104 Punit CE
Combined Projection & Selection Operation
 Example: Display rollno, name & branch of “ME” branch
students.
Student
RollNo Name Branch SPI
101 Raj CE 8
102 Meet ME 9
104 Punit CE 9

Output-1  Branch=‘ME’ (Student)


RollNo Name Branch SPI
102 Meet ME 9

 RollNo, Name, Branch ( Branch=‘ME’ (Student) )


Output-2
RollNo Name Branch
102 Meet ME
Combined Projection & Selection Operation
 Example: Display name, branch and SPI of students whose SPI
is more than 8.
Student
RollNo Name Branch SPI
101 Raj CE 8
102 Meet ME 9
104 Punit CE 9

 Name, Branch, SPI ( SPI>8 (Student) )

Output
Name Branch SPI
Meet ME 9
Punit CE 9
Combined Projection & Selection Operation
 Example: Display name, branch and SPI of students who
belongs to “CE” Branch and SPI is more than 8.
Student
RollNo Name Branch SPI
101 Raj CE 8
102 Meet ME 9
104 Punit CE 9

 Name, Branch, SPI ( Branch=‘CE’ Λ SPI>8 (Student) )


Output
Name Branch SPI
Punit CE 9
Combined Projection & Selection Operation
 Example: Display name of students along with their branch
who belong to either “ME” Branch or “EE” Branch.
Student
RollNo Name Branch SPI
101 Raj CE 8
102 Meet ME 9
104 Punit CE 9
103 Jatin EE 7

 Name, Branch ( Branch=‘ME’ V Branch=‘EE’ (Student) )


Output
Name Branch
Meet ME
Jatin EE
Relational Algebra
Operations
Cartesian Product /
Cross Product
Cartesian Product / Cross Product
 Symbol: × (Cross)
 Notation: Relation-1 (R1) × Relation-2 (R2)
 Operation: It will multiply each tuples of Relation-1 to each
tuples of Relation-2.
 Attributes of Resultant Relation = Attributes of R1 + Attributes
of R2
 Tuples of Resultant Relation = Tuples of R1 * Tuples of R2
Cartesian Product / Cross Product
 Example:
Student Result
RollNo Name Branch RollNo SPI
101 Raj CE 101 8
102 Meet ME 103 9

Student × Result
Student.RollNo Name Branch Result.RollNo SPI
101 Raj CE 101 8
101 Raj CE 103 9
102 Meet ME 101 8
102 Meet ME 103 9

If both relations have some attribute with the same name, it can
be distinguished by combing relation-name.attribute-name.
Cartesian Product / Cross Product
 Example:
Student Result
RollNo Name Branch Sem RollNo SPI BL Rank
101 Raj CE 3 101 8 1 2
102 Meet ME 5 103 9 0 1

 RollNo, Name (Student) ×  RollNo, SPI, BL (Result)


Student.RollNo Name Result.RollNo SPI BL
101 Raj 101 8 1
101 Raj 103 9 0
102 Meet 101 8 1
102 Meet 103 9 0
Cartesian Product / Cross Product
 Example:
Student Result
RollNo Name Branch Sem RollNo SPI BL Rank
101 Raj CE 3 101 8 1 2
102 Meet ME 5 103 9 0 1
103 Om CE 3 105 7 2 3
104 Dhara CE 5

 Branch=‘CE’ Λ Sem=3 (Student) ×  SPI>7 Λ BL<1(Result)


Student.RollNo Name Branch Sem Result.RollNo SPI BL Rank
101 Raj CE 3 103 9 0 1
103 Om CE 3 103 9 0 1
Relational Algebra
Operations
Natural Join
(Inner Join)
Natural Join (Inner Join)
 Symbol:
 Notation: Relation-1 (R1) Relation-2 (R2)
 Operation: Natural join will retrieve consistent data from
multiple relations.
 It combines records from different relations that satisfy a
given condition.

Steps
Step – 1 It performs Cartesian Product
Step – 2 Then it deletes inconsistent tuples
Step – 3 Then it removes an attribute from
duplicate attributes
Natural Join (Inner Join) example
Student Result
RollNo Name Branch RollNo SPI
101 Raj CE 101 8
102 Meet ME 103 9

Student × Result Step 1 : Performs Cartesian Product

Student.RollNo Name Branch Result.RollNo SPI


101 Raj CE 101 8
101 Raj CE 103 9
102 Meet ME 101 8
102 Meet ME 103 9 Step 3 : Removes an attribute

Student Result Step 2 : Removes inconsistent tuples Student Result


Student.RollNo Name Branch Result.RollNo SPI RollNo Name Branch SPI
101 Raj CE 101 8 101 Raj CE 8
Natural Join (Inner Join) example
Branch B𝐫𝐚𝐧𝐜𝐡 × Faculty Step 1 : Performs Cartesian Product

BID BName Head Branch.BID BName Head FID FName Faculty.BID


1 CE Patel 1 CE Patel 1 Raj 1
2 ME Shah 1 CE Patel 2 Meet 2

Faculty 2 ME Shah 1 Raj 1


2 ME Shah 2 Meet 2
FID FName BID
1 Raj 1 B𝐫𝐚𝐧𝐜𝐡 Faculty Step 2 : Removes inconsistent tuples
2 Meet 2 Branch.BID BName Head FID FName Faculty.BID
Step 3 : Removes an attribute 1 CE Patel 1 Raj 1

B𝐫𝐚𝐧𝐜𝐡 Faculty 2 ME Shah 2 Meet 2

BID BName Head FID FName To perform a natural join there


1 CE Patel 1 Raj must be one common attribute
2 ME Shah 2 Meet (column) between two relations.
Write down relational algebras for the following tables

• Relations
• Student (Rno, Sname, Address, City, Mobile)
• Department (Did, Dname)
• Academic (Rno, Did, SPI, CPI, Backlog)
• Guide (Rno, PName, Fid)
• Faculty (Fid, Fname, Subject, Did, Salary)
• List the name of students with their department name and
SPI of all student belong to “CE” department.

 Sname, Dname, SPI ( Dname=‘CE’ (Student (Department Academic)))


Write down relational algebras for the following tables

• Relations
• Student (Rno, Sname, Address, City, Mobile)
• Department (Did, Dname)
• Academic (Rno, Did, SPI, CPI, Backlog)
• Guide (Rno, PName, Fid)
• Faculty (Fid, Fname, Subject, Did, Salary)
• Display the name of students with their project name whose
guide is “A. J. Shah”.

 Sname, Pname ( Fname=‘A.J.Shah’ (Student (Guide Faculty)))


Relational Algebra
Operations
Outer Join
Outer Join
 Operation: In natural join some records are missing, if we
want that missing records than we have to use outer join.
 Types: Three types of Outer Join
1. Left Outer Join
2. Right Outer Join
3. Full Outer Join
Left Outer Join
 Display all the tuples of the left relation even through there
is no matching tuple in the right relation.
 For such kind of tuples having no matching, the attributes of
right relation will be padded with null in resultant relation.
 Example:
Student Result
RollNo Name Branch RollNo SPI
101 Raj CE 101 8
102 Meet ME 103 9

Student Result
RollNo Name Branch SPI
101 Raj CE 8
102 Meet ME null
Left Outer Join example
 Display Name, Salary and Balance of the of all employees.

Employee Customer
ID Name Salary ID Name Balance
2 Meet 15000 1 Raj 5000
3 Jay 20000 2 Meet 8000

 Name, Salary, Balance (Employee Customer)

Output
Name Salary Balance
Meet 15000 8000
Jay 20000 null
Right Outer Join
 Display all the tuples of right relation even through there is
no matching tuple in the left relation.
 For such kind of tuples having no matching, the attributes of
left relation will be padded with null in resultant relation.
 Example:
Student Result
RollNo Name Branch RollNo SPI
101 Raj CE 101 8
102 Meet ME 103 9

Student Result
RollNo Name Branch SPI
101 Raj CE 8
103 null null 9
Right Outer Join example
 Display Name, Salary and Balance of the of all customers.

Employee Customer
ID Name Salary ID Name Balance
2 Meet 15000 1 Raj 5000
3 Jay 20000 2 Meet 8000

 Name, Salary, Balance (Employee Customer)

Output
Name Salary Balance
Raj null 5000
Meet 15000 8000
Full Outer Join
 Display all the tuples of both of the relations. It also pads
null values whenever required. (Left outer join + Right outer
join)
 For such kind of tuples having no matching, it will be padded
with null in resultant relation.
 Example: Student Result
RollNo Name Branch RollNo SPI
101 Raj CE 101 8
102 Meet ME 103 9

Student Result
RollNo Name Branch SPI
101 Raj CE 8
102 Meet ME null
103 null null 9
Full Outer Join example
 Display Name, Salary and Balance of the of all employee as
well as customers.
Employee Customer
ID Name Salary ID Name Balance
2 Meet 15000 1 Raj 5000
3 Jay 20000 2 Meet 8000

 Name, Salary, Balance (Employee Customer)

Output
Name Salary Balance
Meet 15000 8000
Jay 20000 null
Raj null 5000
Relational Algebra
Operations
Set Operators
Set Operators
 Set operators combine the results of two or more queries
into a single result.
 Types of set operators
1. Union
2. Intersect (Intersection)
3. Minus (Set Difference)
Union Operator
 Symbol: U
 Notation: Relation1 U Relation2
 Operation: Combine the records from two or more queries in
to a single result.

Customer Employee Customer U Employee


Name Name Name
Raj Meet Manoj
Suresh Suresh Meet
Meet Manoj Raj
Suresh

Union removes duplicate records.


Union example
 Display Name of person who are either employee or
customer.
Employee Customer
ID Name Salary ID Name Balance
2 Meet 15000 1 Raj 5000
3 Jay 20000 2 Meet 8000

 Name (Employee) U  Name (Customer)


Output
Name
Meet
Jay
Raj
Intersect Operator
 Symbol: ∩
 Notation: Relation1 ∩ Relation2
 Operation: Returns the records which are common from both
queries.

Customer Employee Customer ∩ Employee


Name Name Name
Raj Meet Meet
Suresh Suresh Suresh
Meet Manoj
Intersect example
 Display Name of person who are employee as well as
customer.
Employee Customer
ID Name Salary ID Name Balance
2 Meet 15000 1 Raj 5000
3 Jay 20000 2 Meet 8000

 Name (Employee) ∩  Name (Customer)


Output
Name
Meet
Minus (Set Difference) Operator
 Symbol: −
 Notation: Relation1 − Relation2
 Operation: Returns all the records from first (left) query that
are not contained in the second (right) query.

Customer Employee Customer − Employee Employee − Customer


Name Name Name Name
Raj Meet Raj Manoj
Suresh Suresh
Meet Manoj
Minus example
 Display Name of person who are employee but not customer.

Employee Customer
ID Name Salary ID Name Balance
2 Meet 15000 1 Raj 5000
3 Jay 20000 2 Meet 8000

 Name (Employee) -  Name (Customer)


Output
Name
Jay
Minus example
 Display Name of person who are customer but not employee.

Employee Customer
ID Name Salary ID Name Balance
2 Meet 15000 1 Raj 5000
3 Jay 20000 2 Meet 8000

 Name (Customer) -  Name (Employee)


Output
Name
Raj
Conditions to perform Set Operators
 Set operators will take two or more queries as input, which
must be union - compatible :
1. Both queries should have same (equal) number of columns

RollNo Name Branch SPI EmpNo Name Branch


101 Raj CE 8 101 Patel CE
102 Meet CE 7 102 Shah CE
103 Neel ME 9 103 Ghosh EE

RollNo Name Branch SPI EmpNo Name Branch Exp


101 Raj CE 8 101 Raj CE 8
102 Meet CE 7 102 Meet CE 1
103 Neel ME 9 103 Ghosh EE 9
Conditions to perform Set Operators
 Set operators will take two or more queries as input, which
must be union - compatible:
2. Corresponding attributes should have the same data type

RollNo Name Branch SPI EmpNo Name Branch Subject


101 Raj CE 8 101 Raj CE DBMS
102 Meet CE 7 102 Meet CE DS
103 Neel ME 9 103 Ghosh EE EEM

RollNo Name Branch SPI EmpNo Name Branch Exp


101 Raj CE 8 101 Raj CE 8
102 Meet CE 7 102 Meet CE 1
103 Neel ME 9 103 Ghosh EE 9
Set Operators
 Person (PersonID, Name, Address, Hobby)
 Professor (ProfessorID, Name, Office, Salary)
• are not union compatible.
But
 Name (Person) &  Name (Professor)
• are union compatible.
Relational Algebra
Operations
Division Operator
Division Operator
 Symbol: ÷
 Notation: Relation1 ÷ Relation2
 Condition to perform operation:
• Attributes of relation2 is proper subset of attributes of relation1.
 Operation:
• The output of the division operator will have attributes =
All attributes of relation1 – All attributes of relation2
• The output of the division operator will have tuples =
Tuples in relation1, which are associated with the all tuples of
relation2.
Division Operator example
Student Subject Student ÷ Subject
Name Subject Subject Name
Raj DBMS DBMS Meet
Raj DS DS Suresh
Meet DBMS DE
Meet DS
Meet DE
Suresh DBMS
Suresh DS
Suresh DE
Rohit DS
Rohit DE
Division Operator example
A B1 B2 B3
Sno Pno Pno Pno Pno
S1 P1 P2 P2 P1
S1 P2 P4 P2
S1 P3 P4
S1 P4
S2 P1 A ÷ B1 A ÷ B2 A ÷ B3
S2 P2 Sno Sno Sno
S3 P2 S1 S1 S1
S4 P2 S2 S4
S4 P4 S3
S5 P4 S4
List the name of students doing a project in all technologies

Student Project
Rno Name Technology TID Technology
101 Raj .NET 1 .NET
101 Raj iPhone 2 PHP
102 Meet .NET 3 iPhone
102 Meet PHP 4 Android
102 Meet iPhone
102 Meet Android
103 Vijay PHP Output
104 Jay .NET Name
104 Jay PHP Meet
104 Jay iPhone Jay
104 Jay Android

 Name, Technology (Student) ÷  Technology(Project)


Relational Algebra
Operations
Rename Operator
Rename Operator
 Symbol: ρ (Rho)
 Notation: ρ A (X1,X2….Xn) (Relation)
 Operation: The rename operator returns an existing relation
under a new name.
 How to use:
• ρ x (E)
• Returns a relation E under a new name X.

• ρ A1, A2. …,An (E)


• Returns a relation E with the attributes renamed to A1, A2, …., An.

• ρ x(A1, A2. …,An) (E)


• Returns a relation E under a new name X with the attributes renamed to A1,
A2, …., An.
Rename Operator example (Relation)
Student
Rno Name CPI
101 Raj 8
102 Meet 9
103 Suresh 7

ρPerson (Student)

Person
Rno Name CPI
101 Raj 8
102 Meet 9
103 Suresh 7
Rename Operator example (Attribute)
Student
Rno Name CPI
101 Raj 8
102 Meet 9
103 Suresh 7

ρ (RollNo, StudentName, CPI) (Student)

Student
RollNo StudentName CPI
101 Raj 8
102 Meet 9
103 Suresh 7
Rename Operator example (Attribute & Relation both)

Student
Rno Name CPI
101 Raj 8
102 Meet 9
103 Suresh 7

ρPerson (RollNo, StudentName) ( RNo, Name (Student))

Person
RollNo StudentName
101 Raj
102 Meet
103 Suresh
Rename Operator example
Rno Name CPI
Find out maximum CPI from student table.
101 Raj 8
102 Meet 9 ρA (Student) X ρB (Student)))
103 Suresh 7

A.Rno A.Name A.CPI B.Rno B.Name B.CPI


101 Raj 8 101 Raj 8
101 Raj 8 102 Meet 9
101 Raj 8 103 Suresh 7
102 Meet 9 101 Raj 8
102 Meet 9 102 Meet 9
102 Meet 9 103 Suresh 7
103 Suresh 7 101 Raj 8
103 Suresh 7 102 Meet 9
103 Suresh 7 103 Suresh 7
Rename Operator example

 A.CPI<B.CPI (ρA (Student) X ρB (Student)))

A.Rno A.Name A.CPI B.Rno B.Name B.CPI


101 Raj 8 101 Raj 8
101 Raj 8 102 Meet 9
101 Raj 8 103 Suresh 7
102 Meet 9 101 Raj 8
102 Meet 9 102 Meet 9
102 Meet 9 103 Suresh 7
103 Suresh 7 101 Raj 8
103 Suresh 7 102 Meet 9
103 Suresh 7 103 Suresh 7
Rename Operator example

 A.CPI<B.CPI (ρA (Student) X ρB (Student)))

A.Rno A.Name A.CPI B.Rno B.Name B.CPI


101 Raj 8 101 Raj 8
101 Raj 8 102 Meet 9
101 Raj 8 103 Suresh 7
102 Meet 9 101 Raj 8
102 Meet 9 102 Meet 9
102 Meet 9 103 Suresh 7
103 Suresh 7 101 Raj 8
103 Suresh 7 102 Meet 9
103 Suresh 7 103 Suresh 7
Rename Operator example

 A.CPI<B.CPI (ρA (Student) X ρB (Student)))

A.Rno A.Name A.CPI B.Rno B.Name B.CPI


101 Raj 8 102 Meet 9
103 Suresh 7 101 Raj 8
103 Suresh 7 102 Meet 9
Rename Operator example

∏A.CPI ( A.CPI<B.CPI (ρA (Student) X ρB (Student)))

A.Rno A.Name A.CPI B.Rno B.Name B.CPI


101 Raj 8 102 Meet 9
103 Suresh 7 101 Raj 8
103 Suresh 7 102 Meet 9
Rename Operator example

∏A.CPI ( A.CPI<B.CPI (ρA (Student) X ρB (Student)))

A.CPI
8
7
Rename Operator example

∏CPI (Student) ─ ∏A.CPI ( A.CPI<B.CPI (ρA (Student) X ρB (Student)))

CPI A.CPI CPI


8 8 9
— = =
9 7
7
Relational Algebra
Operations
Aggregate Functions
Aggregate Functions
 Symbol: g or G
 Notation: g function-name (column) (Relation)
 Operation: It takes a more than one value as input
and returns a single value as output (result).
• Aggregate functions are:
1. Sum (It returns the sum (addition) of the values of a column.)
2. Max (It returns the maximum value for a column.)
3. Min (It returns the minimum value for a column.)
4. Avg (It returns the average of the values for a column.)
5. Count (It returns total number of values in a given column.)
Aggregate Functions example
Student
Rno Name Branch Semester CPI
101 Ramesh CE 3 9
102 Mahesh EC 3 8
103 Suresh ME 4 7
104 Amit EE 4 8
105 Anita CE 4 8
106 Reeta ME 3 7
107 Rohit EE 4 9
108 Chetan CE 3 8
109 Rakesh CE 4 9

 Example: Find out sum of CPI of all students.


sum
• G sum(CPI) (Student)
73
Aggregate Functions example
Student
Rno Name Branch Semester CPI
101 Ramesh CE 3 9
102 Mahesh EC 3 8
103 Suresh ME 4 7
104 Amit EE 4 8
105 Anita CE 4 8
106 Reeta ME 3 7
107 Rohit EE 4 9
108 Chetan CE 3 8
109 Rakesh CE 4 9

 Example: Find out maximum & minimum CPI.


max min
• G max(CPI), min(CPI) (Student)
9 7
Aggregate Functions example
Student
Rno Name Branch Semester CPI
101 Ramesh CE 3 9
102 Mahesh EC 3 8
103 Suresh ME 4 7
104 Amit EE 4 8
105 Anita CE 4 8
106 Reeta ME 3 7
107 Rohit EE 4 9
108 Chetan CE 3 8
109 Rakesh CE 4 9

 Example: Count the number of students.


count
• G count(Rno) (Student)
9
Open Source and
Commercial DBMS
Open Source and Commercial DBMS
Open Source Commercial
DBMS, which is available in DBMS, which is available in
the market at free of cost. the market at a certain price.
The code of open source The code of commercial
DBMS product can be viewed, DBMS product can not be
shared or modified by the view, share or modify by the
community. community.
There are chances of The security is high and code
malfunctioning with code as is not accessible to
source code is open. unauthorized person.
Examples: MySQL, MongoDB, Examples: Microsoft SQL
SQLite etc Server, IBM Db2 etc

You might also like