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 :
- [Time] (start time)
- [From] (caller number)
- [To] (target number)
- [Cost] (in money)
- [Length] (how long called)
The columns of interest here are [From] and [To].
In the second database(rtc - this is a Lync persistent data DB) there are three tables of interest :
- Resource (matches ResourceID to Username)
- ResourceDirectory (defines the Time a ResourceID was Inserted and when it was last Updated)
- ResourcePhone (matches a ResouceID to a phonenumber)
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.
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.