Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational Algebra.

Similar presentations


Presentation on theme: "Relational Algebra."— Presentation transcript:

1 Relational Algebra

2 Consider the following relations:
Student(ssn, name, address, major) Course(code, title) Registered(ssn,code) In join example remember that join Denoted by R F S

3 1. List the codes of courses in which at least one student is registered (registered courses):
πcode ( Registered)

4 2. List the titles of registered courses (of those in 1.)
Π title ( Course ∞ Registered )

5 3. List the codes of courses for which no student is registered
πcode ( Course ) - πcode ( Registered )

6 4. The titles of courses for which no student is registered.
In the previous query we found the codes; natural join with Course to find the titles. Π title ( (πcode ( Course ) - πcode ( Registered )) ∞ Course)

7 5. Names of students and the titles of courses they registered to.
πname,title ( Student ∞ Registered ∞ Course)

8 6. SSNs of students who are registered for ‘Database Systems’ or ‘Analysis of Algorithms’.
πssn ( Student ∞ Registered ∞ (σ title=’Database Systems’ Course)) ∪ πssn ( Student ∞ Registered ∞ (σ title=’Analysis of Algorithms’ Course))

9 7. SSNs of students who are registered for both ‘Database Systems’ and ‘Analysis of Algorithms’.
πssn ( Student ∞ Registered ∞ (σ title=’Database Systems’ Course)) ∩ πssn ( Student ∞ Registered ∞ (σ title=’Analysis of Algorithms’ Course)) The name of those students: A=πssn ( Student ∞ Registered ∞ (σ title=’Database Systems’ Course)) ∩ πssn ( Student ∞ Registered ∞ (σ title=’Analysis of Algorithms’ Course)) πname ( A ∞ Student) used A= instead of ρ( ) function.


Download ppt "Relational Algebra."

Similar presentations


Ads by Google