title: Loop through SQL query using variable from another table
body: <p>I have two tables file &amp; users, I want to see the file info for each user for <code>C:\Users\%USERNAME%\Documents</code></p>
  
  <p>So e.g. this would get the info from 'example' documents:</p>
  
  <pre><code>SELECT * 
  FROM file 
  WHERE path LIKE 'C:\Users\example\Documents\%%';
  </code></pre>
  
  <p>But the username is coming from the users </p>
  
  <pre><code>SELECT username FROM users;
  </code></pre>
  
  <p>returns</p>
  
  <pre><code>+--------------------+
  | username           |
  +--------------------+
  | Administrator      |
  | DefaultAccount     |
  | example            |
  | Guest              |
  | WDAGUtilityAccount |
  | SYSTEM             |
  | LOCAL SERVICE      |
  | NETWORK SERVICE    |
  +--------------------+
  </code></pre>
  
  <p>Alternatively, there's:</p>
  
  <pre><code>SELECT directory FROM users;
  
  +---------------------------------------------+
  | directory                                   |
  +---------------------------------------------+
  |                                             |
  |                                             |
  | C:\Users\example                            |
  |                                             |
  |                                             |
  | %systemroot%\system32\config\systemprofile  |
  | %systemroot%\ServiceProfiles\LocalService   |
  | %systemroot%\ServiceProfiles\NetworkService |
  +---------------------------------------------+
  </code></pre>
  
  <p>Which provides the first part of the path, but still can't get to join 'Documents' to end of query and also run the file query.</p>
  
  <p>So, how do I loop through the each of the usernames.</p>
  
  <p>I've tried modifying but neither table can be modified</p>