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.

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.

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)

and what is the query ?

in which part you are going to use relational algebra ?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.