Skip to content
Advertisement

How to compare two sets in MySQL or SQL SERVER?

In this University Database:

I have this question:

Find names and IDs of students who have had ALL the courses that teacher Sullivan has taught.

I can easily find the answer with relational algebra:

  1. How do I implement the Division operator in SQL?

And our teacher gave us this answer for SQL SERVER:

And from the slides of our online class, this is what they mean by CONTAINS:

Contains

  1. But from what I have googled, the contains function has nothing to do with sets, it seems to be a full-indexed test searching function. Please correct me if I’m wrong.

After a while, I came up with this solution:

Advertisement

Answer

Gag. This would seem to answer the question:

Let me say that I’m not impressed with the teacher:

  • Never use commas in the FROM clause.
  • Always use proper, explicit, standard, readable JOIN syntax.
  • CONTAINS() is a SQL Server full-text function. It doesn’t exist in MySQL. And I have not heard of its use as a set operator.
  • Spaces after the . is non-standard . . . and I would suggest table aliases as well.
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement