Question

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 points of advice would be much appreciated.

Was it helpful?

Solution

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)

OTHER TIPS

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 = ''
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top