title: SQL get common values in a database
body: <p>I'm using Sqlsrv and I need to find common values within the same table using PHP. There are two main columns, user_id and bssid.</p>
  
  <p>Using a selected $user_id, I need to find all common "bssid" values and return a set of users which contain these values (this is if another user_id has one or more bssid the same).</p>
  
  <p>This is my query string so far. My logic doesn't work.</p>
  
  <pre><code>    $sql = "SELECT A.* FROM AccessPoints A INNER JOIN (SELECT bssid, user_id
          FROM AccessPoints WHERE user_id='$userID'
          GROUP BY bssid, user_id
          HAVING COUNT(*) &gt;= 1) B
          ON A.bssid = B.bssidB.user_id = A.user_id";
  </code></pre>
  
  <p>The database schema is as such:</p>
  
  <p><a href="https://i.stack.imgur.com/Fr1OV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Fr1OV.png" alt="Image of database"></a></p>
  
  <p>A sample of the dataset can be seen as such, and contains the data from two users:</p>
  
  <p><a href="https://i.stack.imgur.com/iKtTE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iKtTE.png" alt="Image of database data entries"></a></p>
  
  <p>I simply want to query a user_id and return all other user_ids which have similar bssids</p>