title: what is the correct order to read SQL where function
body: <p>The goal is to select sales person who did not have any orders related to the company with the name 'Red'</p>
  <p>My question is in the second select (within the where function) why the code didn't include 'from salesperson S'? I am confused since in the second select s.name I didn't define the 's'</p>
  <p>what is the proper order for me to read the attached code?</p>
  <pre><code>SELECT  s.name
  FROM    salesperson s
  WHERE   NOT EXISTS (
      SELECT  s.name 
      FROM    company c, orders o # why not include salesperson s at here ? 
      WHERE   s.sales_id = o.sales_id 
          AND c.com_id = o.com_id
          AND c.name = 'RED'
      );
  </code></pre>
  <p>Input:</p>
  <p>SalesPerson table:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">sales_id</th>
  <th style="text-align: left;">name</th>
  <th style="text-align: left;">salary</th>
  <th style="text-align: left;">commission_rate</th>
  <th style="text-align: left;">hire_date</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">1</td>
  <td style="text-align: left;">John</td>
  <td style="text-align: left;">100000</td>
  <td style="text-align: left;">6</td>
  <td style="text-align: left;">4/1/2006</td>
  </tr>
  <tr>
  <td style="text-align: left;">2</td>
  <td style="text-align: left;">Amy</td>
  <td style="text-align: left;">12000</td>
  <td style="text-align: left;">5</td>
  <td style="text-align: left;">5/1/2010</td>
  </tr>
  <tr>
  <td style="text-align: left;">3</td>
  <td style="text-align: left;">Mark</td>
  <td style="text-align: left;">65000</td>
  <td style="text-align: left;">12</td>
  <td style="text-align: left;">12/25/2008</td>
  </tr>
  <tr>
  <td style="text-align: left;">4</td>
  <td style="text-align: left;">Pam</td>
  <td style="text-align: left;">25000</td>
  <td style="text-align: left;">25</td>
  <td style="text-align: left;">1/1/2005</td>
  </tr>
  <tr>
  <td style="text-align: left;">5</td>
  <td style="text-align: left;">Alex</td>
  <td style="text-align: left;">5000</td>
  <td style="text-align: left;">10</td>
  <td style="text-align: left;">2/3/2007</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Company table:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>com_id</th>
  <th>name</th>
  <th>city</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>RED</td>
  <td>Boston</td>
  </tr>
  <tr>
  <td>2</td>
  <td>ORANGE</td>
  <td>New York</td>
  </tr>
  <tr>
  <td>3</td>
  <td>YELLOW</td>
  <td>Boston</td>
  </tr>
  <tr>
  <td>4</td>
  <td>GREEN</td>
  <td>Austin</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Orders table:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>order_id</th>
  <th>order_date</th>
  <th>com_id</th>
  <th>sales_id</th>
  <th>amount</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>1/1/2014</td>
  <td>3</td>
  <td>4</td>
  <td>10000</td>
  </tr>
  <tr>
  <td>2</td>
  <td>2/1/2014</td>
  <td>4</td>
  <td>5</td>
  <td>5000</td>
  </tr>
  <tr>
  <td>3</td>
  <td>3/1/2014</td>
  <td>1</td>
  <td>1</td>
  <td>50000</td>
  </tr>
  <tr>
  <td>4</td>
  <td>4/1/2014</td>
  <td>1</td>
  <td>4</td>
  <td>25000</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Output:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>name</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Amy</td>
  </tr>
  <tr>
  <td>Mark</td>
  </tr>
  <tr>
  <td>Alex</td>
  </tr>
  </tbody>
  </table>
  </div>