user1079065
user1079065

Reputation: 2205

oracle 10g contains clause

I am new to SQL. I am trying to write a query which requires contains operator. I am looking at many examples for the contains clause, but they seem different than what I need to use. I want a divide operator(relational algebra) equivalent in sql.

a sample of what I am doing is :

Give the students names who are enrolled for computer architecture course and have satisfied all its prerequisites. I have a prereq table and a course table which lists all courses taken by student

so what I ultimately want is (get all courses taken by a student) contains (get all prerequisits)

for what exactly shall I look for for sql equivalent of divide operation in relational algebra?

Upvotes: 0

Views: 258

Answers (1)

Mark Leiber
Mark Leiber

Reputation: 3138

You can do this by comparing counts.

select s.StudentName
from StudentCourses s, PrereqCourses p
where s.CourseId = p.CourseId
group by s.StudentName
having count(*) = (select count(*) from PrereqCourses)

See: http://www.dba-oracle.com/t_sql_patterns_relational_division.htm

Upvotes: 1

Related Questions