title: Can someone please explain the query shown in depth?
body: <p>Question: write a SQL query to find the salespeople from the given tables who had more than one customer. Return <code>salesman_id</code> and <code>name</code>.</p>
  <p>Sample table: <code>customer</code></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>customer_id</th>
  <th>cust_name</th>
  <th>city</th>
  <th>grade</th>
  <th>salesman_id</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>3002</td>
  <td>Nick Rimando</td>
  <td>New York</td>
  <td>100</td>
  <td>5001</td>
  </tr>
  <tr>
  <td>3007</td>
  <td>Brad Davis</td>
  <td>New York</td>
  <td>200</td>
  <td>5001</td>
  </tr>
  <tr>
  <td>3005</td>
  <td>Graham Zusi</td>
  <td>California</td>
  <td>200</td>
  <td>5002</td>
  </tr>
  <tr>
  <td>3008</td>
  <td>Julian Green</td>
  <td>London</td>
  <td>300</td>
  <td>5002</td>
  </tr>
  <tr>
  <td>3004</td>
  <td>Fabian Johnson</td>
  <td>Paris</td>
  <td>300</td>
  <td>5006</td>
  </tr>
  <tr>
  <td>3009</td>
  <td>Geoff Cameron</td>
  <td>Berlin</td>
  <td>100</td>
  <td>5003</td>
  </tr>
  <tr>
  <td>3003</td>
  <td>Jozy Altidor</td>
  <td>Moscow</td>
  <td>200</td>
  <td>5007</td>
  </tr>
  <tr>
  <td>3001</td>
  <td>Brad Guzan</td>
  <td>London</td>
  <td></td>
  <td>5005</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Sample table: <code>salesman</code></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>salesman_id</th>
  <th>name</th>
  <th>city</th>
  <th>commission</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>5001</td>
  <td>James Hoog</td>
  <td>New York</td>
  <td>0.15</td>
  </tr>
  <tr>
  <td>5002</td>
  <td>Nail Knite</td>
  <td>Paris</td>
  <td>0.13</td>
  </tr>
  <tr>
  <td>5005</td>
  <td>Pit Alex</td>
  <td>London</td>
  <td>0.11</td>
  </tr>
  <tr>
  <td>5006</td>
  <td>Mc Lyon</td>
  <td>Paris</td>
  <td>0.14</td>
  </tr>
  <tr>
  <td>5007</td>
  <td>Paul Adam</td>
  <td>Rome</td>
  <td>0.13</td>
  </tr>
  <tr>
  <td>5003</td>
  <td>Lauson Hen</td>
  <td>San Jose</td>
  <td>0.12</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Solution</p>
  <pre class="lang-sql prettyprint-override"><code>SELECT salesman_id,name 
  FROM salesman a 
  WHERE 1 &lt; (SELECT COUNT(*) 
             FROM customer 
             WHERE salesman_id = a.salesman_id);
  </code></pre>
  <p>So basically am unable to understand the subquery how can we compare two table column without using the joins and secondly how this where condition is working as a group by as well and provide the count. So if someone can help me understand this subquery in depth with easy language then it would be really helpful.</p>
  <p>This question and solution is correct because am practicing on W3resource and you can find this question under the topic of SQL Subquery Exercises in the exercise 11.</p>