views:

319

answers:

2

I have a database assignment which i have to create some relational algebra for two problems. I feel fairly all right with the majority of it, but I just get confused when trying to project attributes out of a table which is joined to another table.

for example is this correct?

Q1) List the details of incidences with no calls made, so that the receptionist knows which incidents still need to be called in.

RESULT <-- PROJECT<STUDENT.FirstName, STUDENT.LastName, STAFF.FirstName, STAFF.INCIDENT.LastName, INCIDENT.DateTimeReported, INCIDENT.NatureOfIllness(SELECTINCIDENT.DecisionMade = ''(Staff RIGHT JOIN<STAFF.StaffID = INCIDENT.StaffID>(INCIDENT LEFT JOIN<INCIDENT.StudentID = STUDENT.StudentID>(STUDENT))))

The SQL which i am trying to interpret into relational algebra is:

SELECT s.FirstName, s.LastName, st.FirstName, st.LastName, i.DateTimeReported, i.NatureOfIllness
FROM Student s RIGHT JOIN Incident i ON s.StudentID = i.StudentID   LEFT JOIN Staff st ON st.StaffID = i.StaffID
WHERE i.DecisionMade = ''

Any pointers of advice would be much appreciated.

+1  A: 

Your version seems correct, except for some typos like STAFF.INCIDENT.LastName. Here's my version:

RESULT <--- 
   PROJECT <STUDENT.FirstName, STUDENT.LastName, 
                     STAFF.FirstName, STAFF.LastName,
                     INCIDENT.DateTimeReported, INCIDENT.NatureOfIllness>
      (SELECT <INCIDENT.DecisionMade = ''> 
         ((STUDENT RIGHT JOIN <STUDENT.StudentID = INCIDENT.StudentID> INCIDENT)
             LEFT JOIN <INCIDENT.StaffID = STAFF.StaffID> STAFF)
Federico Ramponi
Thank you for your correction =]
Malachi
+1  A: 

It's usually (some exceptions apply, of course) easier to read and understand the sql if you write it all with LEFT JOINs:

SELECT s.FirstName, s.LastName, st.FirstName, st.LastName, i.DateTimeReported, i.NatureOfIllness
FROM Incident i
LEFT JOIN Student s ON s.StudentID = i.StudentID
LEFT JOIN Staff st ON st.StaffID = i.StaffID
WHERE i.DecisionMade = ''
Joel Coehoorn
Thank you, I'll read into this =]
Malachi