160 likes | 319 Vues
Database Systems. Relational Algebra – Inner and Outer Joins. Natural join of multiple tables. Select students (Name, CGPA) who are registered in ‘Database’ course. [Note: Need to query on ‘Course Name’ and not on ‘Course Code’]
E N D
Database Systems Relational Algebra – Inner and Outer Joins
Natural join of multiple tables. • Select students (Name, CGPA) who are registered in ‘Database’ course. [Note: Need to query on ‘Course Name’ and not on ‘Course Code’] • Select Students (Name, CGPA) who are currently being taught by Ms. Saleha. • Retrieve all members (Name, Deptt Name) of ‘Publications’ committee (including its faculty incharge).
Natural Join result • In order for a record (in one table)to appear in natural join result, its matching key (PK/FK) must exist in other table. • Records with no matching key will be filtered out during natural join.
FULL OUTER JOIN • Mixture of Left outer join and Right outer join
Exercise • Retrieve faculty information. (Faculty Name, Address, Committee Name (if any) ) • Select all students with CGPA > 3.3 and student committee they belong to. ( If a student is not part of any committee, still his name must appear in the list with committee name as ‘Null’)
Exercise • Retrieve students who have attended all core courses of CS or of CE.
Common Mistakes • Select students who are not registered in ‘CSE341’. • Incorrect: Using <> • Correct: Using DIFFERENCE • Select students who are registered in both CSE341 and CSE455. • Incorrect: Using ‘AND’ condition ( e.g. CourseCode = 341 and CourseCode = 455’ • Correct: Using Intersection • Confusion between Union and Join: • Union increases rows but Join increases columns. • Record must be present in either of table to appear in Union. Whereas in joins, PK of one table must match with FK of other table to come in resultset.
Relational Calculus • Predicate & Proposition • Quantifiers • Existential Quantifier • Universal Quantifier
Exercise • Select rooms that do not have dry-cleaning facility. • Retrieve rooms (RoomNo) having facilities of ‘Balcony’ and ‘Internet Connection’ but not ‘Pick & Drop’. • Retrieve rooms that do not have ‘Dry-cleaning’ facility. • Retrieve rooms (Room No, Description, Per Night Charges) that are located on either 1st or 3rd floor and have per night charges < 5000.