Sorry for the poor headline, I couldn't think of a better way to describe my problem, so I've made up for it by explaining it well with examples.

Setup
-----

If you'd like to follow along, here's the SQL to create the table for my problem:

```
CREATE TABLE `student_sections` (`student_id` int(11) NOT NULL, `section_id` int(11) NOT NULL);
INSERT INTO `student_sections` (`student_id`,`section_id`) VALUES (1,11);
INSERT INTO `student_sections` (`student_id`,`section_id`) VALUES (1,12);
INSERT INTO `student_sections` (`student_id`,`section_id`) VALUES (1,13);
INSERT INTO `student_sections` (`student_id`,`section_id`) VALUES (1,14);
INSERT INTO `student_sections` (`student_id`,`section_id`) VALUES (1,15);
INSERT INTO `student_sections` (`student_id`,`section_id`) VALUES (2,12);
INSERT INTO `student_sections` (`student_id`,`section_id`) VALUES (2,13);
INSERT INTO `student_sections` (`student_id`,`section_id`) VALUES (2,14);
INSERT INTO `student_sections` (`student_id`,`section_id`) VALUES (2,21);
INSERT INTO `student_sections` (`student_id`,`section_id`) VALUES (2,22);
INSERT INTO `student_sections` (`student_id`,`section_id`) VALUES (2,23);

```

This results in the following table:

```
| student_sections        |
|-------------------------|
| student_id | section_id |
|------------|------------|
| 1          | 11         |
| 1          | 12         |
| 1          | 13         |
| 1          | 14         |
| 1          | 15         |
| 2          | 12         |
| 2          | 13         |
| 2          | 14         |
| 2          | 21         |
| 2          | 22         |
| 2          | 23         |

```

Scenario
--------

I have a "group" of Sections for which I must find all Students associated with a combination of Sections. My application will have several "groups" of Sections.

For "Group 1" of section\_id's: (11,12,13,14,15)
Student 1 is associated with all Sections (11,12,13,14,15).
Student 2 is associated with (12,13,14) but not (11,15). 

For "Group 2" of section\_id's: (21,22,23,24,25)
Student 2 is associated with (21,22,23) but not (24,25).

Given section\_id's (12,13,14) I need to select the student\_id's associated with those section\_id's, but not with section\_id's (11,15).

For example, if given section\_id's (12,13,14) I want to select student\_id (2). Even though student\_id 1 is associated with section\_id (12,13,14) she is also associated with 11 and 15, so I don't want her id returned.

The higher purpose of this query is I will use it as a subquery to select lists of students given a combination of sections.

Also for example, if given section\_id's (12,13) no results would be returned.

What I have tried
-----------------

I tried using a mix of IN and NOT IN, but because 5 rows have student\_id 1 and 3 rows associated with (12,13,14) the DISTINT() in the following query returns both student\_id 1 and 2.

```
SELECT
    DISTINCT(student_id)
FROM
    student_sections
WHERE
    section_id IN (12,13,14)
    AND section_id NOT IN (11,15)

```

### Update February 1

I added some additional use case data that slightly changed the requirements of the query. A Student will be scheduled against several "groups" of Sections.