title: Help with complex SQL query (a lot of JOINs?)
body: <p>There are two databases and 4 tables involved in this query. The first database(PhoneBills) contains the first table(CallDetails), and within this there are columns for :</p>
  
  <ol>
  <li>[Time] (start time)</li>
  <li>[From] (caller number)</li>
  <li>[To] (target number)</li>
  <li>[Cost] (in money)</li>
  <li>[Length] (how long called)</li>
  </ol>
  
  <p>The columns of interest here are [From] and [To].</p>
  
  <p>In the second database(rtc - this is a Lync persistent data DB) there are three tables of interest :</p>
  
  <ol>
  <li>Resource (matches ResourceID to Username)</li>
  <li>ResourceDirectory (defines the Time a ResourceID was Inserted and when it was last Updated)</li>
  <li>ResourcePhone (matches a ResouceID to a phonenumber)</li>
  </ol>
  
  <p>I don't honestly know what ResourceDirectory defines, I am guessing that the phone numbers that usernames are matched to can change, and the directory keeps track of those times. For the purposes of simplification, I will ignore this part for now.</p>
  
  <p>What I am trying to achieve is to get the Username from Resource given that I can find a match for my phone number in ResourcePhone.</p>