The answers you seek, my friends, are in the RP_RUN_QUERY and AP_GET_PHONES stored procedures. This piqued my interest as well since I've been digging around the output set logic related to salutations recently.
The "Data From" items in TR_QUERY_ELEMENT that you mention are a kind of virtual tables that are created behind the scenes by RP_RUN_QUERY when you execute an output set. The reason for this is to apply selection logic to things like addresses and salutations based on the parameters you use to execute your query. In the case of phones, I believe the purpose of using the virtual table is that if you have different phones on multiple addresses, the phones returned will be the ones attached to the _address_ that is selected for the constituent (even if no address fields are present in your output).
The other wrinkle here is the actual behavior of AP_GET_PHONES. If you look closely, the return value of Phone 1 (in this procedure known as @day_phone) is actually any phone number for the constituent with a TR_PHONE_TYPE id of 7 — on my system, this is a Work phone (I believe that's what's configured out of the box, but I'm not sure). The return value of Phone 2, in this procedure known as @eve_phone, is... you guessed it, a phone on the selected address with a type ID of 1, which is used for "phone 1" on an address.
It smells like a bug to me, or at the least undocumented behavior. (Who would have guessed that phone type 7 was so special?) But there is one more thing — AP_GET_PHONES actually provides for a DBA to replace its behavior with whatever localized logic you want in LP_GET_PHONES. So you _could_ fix this yourself if you were so inclined! (You could also circumvent the virtual table query elements and make your own elements based on a custom view, but the LP_GET_PHONES proc would give you more options).
P.S. Join us on Slack! Info at https://tessituracoders.bitbucket.io/
It's always in the last place you look! Kevin, perhaps there should be reference to ID 7's special behavior in the TR_PHONE_TYPE table documentation. I was scouring the documentation around output sets and query elements, and I'm not sure there's anything that would bring you to those standard data output docs if you didn't know what you were looking for already.
This behavior for the return of phone numbers is documented on the Phones screen: http://www.tessituranetwork.com/Help_System_v125/Content/Constituent%20Records%20Basic%20Features/Phones%20Screen.htm
It’s also noted at the top of any of the topics listing the standard data output for things like acknowledgements, confirmations, renewal notices, and extractions.
Kevin Sheehan
Senior Technical Writer & Consultant
Tessitura Network
+1 888 643 5778 x 329
ksheehan@tessituranetwork.com