GROUP 04
INTRODUCTION TO RELATIONAL ALGEBRA
SELECTION AND PROJECTION
BRIEF EXPLANATION
• Relational database systems are expected to be equipped with a query
language that can assist its users to query the database instances.
• There are two kinds of query languages which are namely relational
algebra and relational calculus.
As group 4 we are presenting on RELATIONAL ALGEBRA
RELATIONAL ALGEBRA
• Relational algebra is a procedural query language, which takes instances of relations as input
and yields instances of relations as output. It uses operators to perform queries.
• They accept relations as their input and yield relations as their output. Relational algebra is
performed recursively on a relation and intermediate results are also considered relations.
• In database theory, relational algebra is a theory that uses algebraic structures with a well-
founded semantics for modeling data, and defining queries on it.
• Every DBMS must define a query language to enable users to access the data which is stored
in the database. Relational Algebra is a procedural query language.
RELATIONAL ALGEBRA
The fundamental operations of relational algebra are as follows :
• Select
• Project
• Union
• Set different
• Cartesian product
1) SELECTION OPERATION
• It selects tuples that satisfy the given predicate from a relation.
• Selection also means picking certain rows.
Notation − σp(r)
• Where σ stands for selection predicate and r stands for relation. p is
prepositional logic formula which may use connectors like and, or, and not.
These terms may use relational operators like − =, ≠, ≥, < , >, ≤.
EXAMPLE FOR SELECTION
A) σsubject = "database"(Books)
Output − Selects tuples from books where subject is 'database'.
--------------------------------------------------------------------------------------------------
B) σsubject = "database" and price = "450"(Books)
Output − Selects tuples from books where subject is 'database' and
'price' is 450.
.
TABLE 3: STUDENTS
ROLL_NO NAME ADDRESS PHONE AGE
1 RAM DELHI 9455123451 18
2 RAMESH GURGAON 9652431543 18
3 SUJIT ROHTAK 9156253131 20
4 SURESH DELHI 9156768971 18
CONT……..
• σ (AGE>18)(STUDENTS)
• SELECT operator does not show any result, the projection operator must
be called before the selection operator to generate or project the result. So,
the correct syntax to generate the result is: ∏(σ (AGE>18)(STUDENT))]
• RESULT:
ROLL_NO NAME ADDRESS PHONE AGE
3 SUJIT ROHTAK 9156253131 20
2) PROJECT OPERATION (∏)
• It projects column(s) that satisfy a given predicate.
• Notation − ∏A1, A2, An (r)
• Where A1, A2 , An are attribute names of relation r.
• Duplicate rows are automatically eliminated, as relation is a set.
EXAMPLE FOR PROJECTION
• ∏subject, author (Books)
= Selects and projects columns named as subject and author from
the relation Books.
TABLE 3: STUDENT
ROLL_NO NAME ADDRESS PHONE AGE
1 RAM DELHI 9455123451 18
2 RAMESH GURGAON 9652431543 18
3 SUJIT ROHTAK 9156253131 20
4 SURESH DELHI 9156768971 18
THIS OPERATION SHOWS THE LIST OF THOSE ATTRIBUTES THAT WE WISH TO
APPEAR IN THE RESULT. REST OF THE ATTRIBUTES ARE ELIMINATED FROM
THE TABLE.
IT IS DENOTED BY ∏.
ROLL_NO NAME
1 RAM
2 RAMESH
3 SUJIT
4 SURESH
∏(ROLL_NO,NAME)(STUDENT)
RESULT:
CONT…….
• Note: If the resultant relation after projection has duplicate rows, it will be
removed.
EXTENDED PROJECTION
CONT…….
GROUP 04
THANK YOU !!

GROUP 4 RELATIONAL ALGEBRA.pptx

  • 1.
    GROUP 04 INTRODUCTION TORELATIONAL ALGEBRA SELECTION AND PROJECTION
  • 2.
    BRIEF EXPLANATION • Relationaldatabase systems are expected to be equipped with a query language that can assist its users to query the database instances. • There are two kinds of query languages which are namely relational algebra and relational calculus. As group 4 we are presenting on RELATIONAL ALGEBRA
  • 3.
    RELATIONAL ALGEBRA • Relationalalgebra is a procedural query language, which takes instances of relations as input and yields instances of relations as output. It uses operators to perform queries. • They accept relations as their input and yield relations as their output. Relational algebra is performed recursively on a relation and intermediate results are also considered relations. • In database theory, relational algebra is a theory that uses algebraic structures with a well- founded semantics for modeling data, and defining queries on it. • Every DBMS must define a query language to enable users to access the data which is stored in the database. Relational Algebra is a procedural query language.
  • 4.
    RELATIONAL ALGEBRA The fundamentaloperations of relational algebra are as follows : • Select • Project • Union • Set different • Cartesian product
  • 5.
    1) SELECTION OPERATION •It selects tuples that satisfy the given predicate from a relation. • Selection also means picking certain rows. Notation − σp(r) • Where σ stands for selection predicate and r stands for relation. p is prepositional logic formula which may use connectors like and, or, and not. These terms may use relational operators like − =, ≠, ≥, < , >, ≤.
  • 6.
    EXAMPLE FOR SELECTION A)σsubject = "database"(Books) Output − Selects tuples from books where subject is 'database'. -------------------------------------------------------------------------------------------------- B) σsubject = "database" and price = "450"(Books) Output − Selects tuples from books where subject is 'database' and 'price' is 450. .
  • 7.
    TABLE 3: STUDENTS ROLL_NONAME ADDRESS PHONE AGE 1 RAM DELHI 9455123451 18 2 RAMESH GURGAON 9652431543 18 3 SUJIT ROHTAK 9156253131 20 4 SURESH DELHI 9156768971 18
  • 8.
    CONT…….. • σ (AGE>18)(STUDENTS) •SELECT operator does not show any result, the projection operator must be called before the selection operator to generate or project the result. So, the correct syntax to generate the result is: ∏(σ (AGE>18)(STUDENT))] • RESULT: ROLL_NO NAME ADDRESS PHONE AGE 3 SUJIT ROHTAK 9156253131 20
  • 9.
    2) PROJECT OPERATION(∏) • It projects column(s) that satisfy a given predicate. • Notation − ∏A1, A2, An (r) • Where A1, A2 , An are attribute names of relation r. • Duplicate rows are automatically eliminated, as relation is a set.
  • 10.
    EXAMPLE FOR PROJECTION •∏subject, author (Books) = Selects and projects columns named as subject and author from the relation Books.
  • 11.
    TABLE 3: STUDENT ROLL_NONAME ADDRESS PHONE AGE 1 RAM DELHI 9455123451 18 2 RAMESH GURGAON 9652431543 18 3 SUJIT ROHTAK 9156253131 20 4 SURESH DELHI 9156768971 18
  • 12.
    THIS OPERATION SHOWSTHE LIST OF THOSE ATTRIBUTES THAT WE WISH TO APPEAR IN THE RESULT. REST OF THE ATTRIBUTES ARE ELIMINATED FROM THE TABLE. IT IS DENOTED BY ∏. ROLL_NO NAME 1 RAM 2 RAMESH 3 SUJIT 4 SURESH ∏(ROLL_NO,NAME)(STUDENT) RESULT:
  • 13.
    CONT……. • Note: Ifthe resultant relation after projection has duplicate rows, it will be removed.
  • 14.
  • 15.
  • 16.