Help writing the following query to relational algebra

rdbmsrelational-theory

Can someone help me in writing the following query to relational algebra, I am studying DBMS and I am stuck on this exercise.

Query:

SELECT a.name, d.name. d.grade
FROM student a, enrolled i, class d
WHERE a.id= i.student_id
AND i.disc_id = d.id

Thanks

Best Answer

This line represents a cartesian product of 3 tables:

FROM student a, enrolled i, class d

After creating a cartesian product you filter out rows that match the predicate.

WHERE a.id= i.student_id
AND i.disc_id = d.id

If you look closer at this query it is equivalent to:

  SELECT a.name, d.name. d.grade
    FROM student a
      JOIN enrolled i ON a.id= i.student_id
      JOIN class d ON i.disc_id = d.id

Maybe you should analyze the second query.

Related Question