title: Find the sids of the suppliers who supply every part
body: <p>3 tables: Suppliers(sid, sname, address), Parts(pid, pname, colour), Catalog(sid, pid, cost)</p>
  
  <p>The answer to find all the suppliers who supply every part is: </p>
  
  <pre><code>SELECT  C.sid
    FROM  Catalog C
    WHERE NOT EXISTS (
       SELECT  P.pid
         FROM  Parts P
         WHERE NOT EXISTS (
           SELECT  C1.sid
             FROM  Catalog C1
             WHERE C1.sid = C.sid
               AND C1.pid = P.pid
           )
       )
  </code></pre>
  
  <p>Could someone explain this answer to me? I'm just a bit lost!</p>
  
  <p>I've heard it explained as 'Find suppliers such that there does not exist
  a part that they do not sell', but I'm struggling to see how </p>
  
  <pre><code>SELECT  C1.sid
             FROM  Catalog C1
             WHERE C1.sid = C.sid
               AND C1.pid = P.pid
           )
  </code></pre>
  
  <p>accomplishes that.</p>
  
  <p>So if I have a </p>
  
  <p><strong>Catalog Table</strong></p>
  
  <p>James | Hammer</p>
  
  <p>James | Anvil</p>
  
  <p>James | Wrench</p>
  
  <p>Henry | Hammer</p>
  
  <p>Leroy | Anvil</p>
  
  <p><strong>Part Table</strong></p>
  
  <p>Hammer</p>
  
  <p>Anvil</p>
  
  <p>Wrench</p>
  
  <p>Then after the innermost clause what is returned exactly?</p>
  
  <p>Is it </p>
  
  <p>James | Hammer</p>
  
  <p>James | Anvil</p>
  
  <p>James | Wrench</p>
  
  <p>Henry | Hammer</p>
  
  <p>Leroy | Anvil</p>
  
  <p>and then NOT EXISTS makes it</p>
  
  <p>James | --</p>
  
  <p>Henry | Anvil, Wrench</p>
  
  <p>Leroy | Hammer, Wrench?</p>
  
  <p>How does the Parts table then subtract these values? Sorry if these questions aren't too clear I'm still new to SQL.</p>