I have a following tables, where primary keys are bolded.
student (SID, SName, semester)
studies (SID, CID)
course (CID, CName, CCode)
Write the SQL queries and Relational Algebra for the following statements.
- Find the names of all students in 'third' semester.
- Find the names of all courses studied by 'Ram'.
- Find the total number of students who study 'DBMS'.
Queries that I tried:
SQL:
SELECT SName FROM student WHERE semester='third'
-
SELECT CNAME FROM student s, studies st, course c WHERE s.SID = st.SID AND st.SID = c.CID AND SName = 'Ram'
-
SELECT count(*) FROM student s, studies st, course c WHERE s.SID = st.SID AND st.SID = c.CID AND CName = 'DBMS'
Relational Algebra:
∏ Sname (σ semester='third' (student))
∏ Cname (σ Sname='Ram' (student ⋈ studies ⋈ course))
ρ count(*) (σ Cname='DBMS' (student ⋈ studies ⋈ course))
Are the queries that I have written correct? If they are wrong, what is the correct solution?