0

I was trying to solve this query:
Find all the students who have taken the course taken by a instructor named 'XXX'.
Well the division operator of relational algebra can do it easily. I want to know how to use the division operator in sql(if there is any) or any other way that works on the same principle.

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by pratik_garg
0

I don't understand why you need to use any division operator and why you need any relational algebra.

Kindly post the query that you are working on.

0

I don't understand why you need to use any division operator and why you need any relational algebra.

Kindly post the query that you are working on.

the query is:
Find the students who have taken all the courses taught by instructor 'Srinivasan'.
The tables have the schema
for student
student(id,name,dept_name)
takes(id,course_id,grade)

for instructor
instructor(id,name,dept_name)
teaches(id,course_id)

0

it is very simple and by a single query solve this problem without using division operator (i am sorry if i didn't understand your question currectly, if you want to solve this only by the help of division operator)

select *
  from student
 where id not in  --[B](1)[/B]
                (select id
                    from takes
                   where course_id not in --[B](2)[/B]          
                        (select course_id
                            from teaches
                           where id = (select id
                                         from instructor
                                        where name = 'Srinivasan'
                                          and rowid = 1)))--[B]if you have two teacher having name as Srinivasan (restricting multiple rows here).[/B]

simply i am selecting information about student which do not fit on our condition (2) and then we are filtering them (1).

-----------
pratik garg

Edited by pratik_garg: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.