TTM and its companion book DTATRM talk about an IMAGE RELATION function, that joins two relations, embedding matching tuples from the right as a relation-valued attribute of the left.
Here is a piece of code that creates an RVA. The relation exam_mark is partitioned across the several courses.
cer := course [{ CourseId, ExamResult := {{ * }} joinr exam_mark}] CourseId | ExamResult ---------------------------------- C1 | StudentId | Mark | --------------------- | S1 | 85 | S2 | 49 | S4 | 93 C2 | StudentId | Mark | --------------------- | S1 | 49 C3 | StudentId | Mark | --------------------- | S3 | 66 C4 | StudentId | Mark | ---------------------
Here is a piece of code that does the job of putting the tuples back together again.
cer [{ fold(union,ExamResult) }] StudentId | Mark --------------------- S1 | 85 S2 | 49 S4 | 93 S1 | 49 S3 | 66
Note that this relies on an anonymous attribute, which is ‘lifted’ out as a single value.