title: Sequelize - Matching all records of a given entity in mySQL database
body: <p>I have three MySQL (v8) tables</p>
  
  <p>TABLE 1:</p>
  
  <pre><code>students (contains details of all students)
  - id
  - full_name
  - email
  </code></pre>
  
  <p>Records:</p>
  
  <pre><code>| id | full_name | email             |
  |----|-----------|-------------------|
  | 1  | John      | john@example.com  |
  | 2  | Adam      | adam@example.com  |
  | 3  | James     | james@example.com |
  | 4  | Jane      | jane@example.com  |
  </code></pre>
  
  <p>TABLE 2:</p>
  
  <pre><code>courses (contains all courses)
  - id
  - title
  </code></pre>
  
  <p>Records:</p>
  
  <pre><code>| id | title  |
  |----|--------|
  | 1  | PHP    |
  | 2  | Python |
  | 3  | .Net   |
  | 4  | HTML   |
  </code></pre>
  
  <p>TABLE 3:</p>
  
  <pre><code>student_courses (this table contains which student has subscribed to what courses)
  - student_id
  - course_id
  </code></pre>
  
  <p>Records:</p>
  
  <pre><code>| id | student_id | course_id |
  |----|------------|-----------|
  | 1  | 1          | 1         |
  | 2  | 1          | 2         |
  | 3  | 2          | 3         |
  | 4  | 3          | 1         |
  </code></pre>
  
  <p>The problem I am facing here is I need to get a list of all students who have opted for both course ids 1 &amp; 2, which in the above example is "John".</p>
  
  <p>Using sequelize I have tried the following two where clauses, but both giving me incorrect results.</p>
  
  <p>Option 1) This is giving me empty result set</p>
  
  <pre><code>where: {
      course_id: {
          [Op.and]: [1,2]
      }
  }
  </code></pre>
  
  <p>Option 2) This is returning "John" as well as "James". It shouldn't return "James" since he has subscribed to only course id 1.</p>
  
  <pre><code>where: {
      course_id: [1, 2]
  }
  </code></pre>
  
  <p>What am I missing here?</p>
  
  <p>Thanks in advance</p>