Parent: User_Session key session_id, each row is a game session that has 2 related players.
Child: User_Session_Player ref to parent via ref_session_id, each row is a player’s parameters, including a spirit they played, which is a ref to SI_Spirit table via ref_spirit_id
SI_Spirit key spirit_id, contains a link to an image [image_spirit] for each spirit as images/imagename.png
The challenge:
For a table-view of User_Session (the parent) I want to show the image for each character in a column, but for clarity’s sake I SORT alphabetically (by SI_Spirit[name]) so that the first column will always contain the spirit image that is earlier alphabetically.
The problem is currently solved with this code:
ANY(
SELECT(SI_Spirit[image_spirit],[spirit_id]=
INDEX(
ORDERBY(
SELECT(User_Session_Player[ref_spirit_id],[ref_session_id]=[_THISROW].[session_id]),
[name]),
1)
)
)
(INDEX,1) for the first column, INDEX(,2) for the second.
I was hoping to leverage [Related User_Session_Players] but the resulting expressions were either equally or more complex (but maybe more efficient?).
What’s the best way to achieve this kind of lookup?