Joins · Left-Join (lj), Inner-Join (ij), Plus-Join (pj) · Practice Question
Combine Shared Columns with Plus-Join
Question
Using the same t and codes2 (with its age:100 column) from the previous question, how would you add the age column from both tables together, rather than having one overwrite the other?
t:([] names:`Tom`Mary`Jack`Sean`Anne`Roy;
country:`Ireland`England`France`England`Germany`Scotland;
age:10 13 14 18 21 41;
employed:101101b)
codes:([] Country:`Ireland`England`France`Germany`Scotland;
digits:("+353";"+44";"+33";"+49";"+44"))
codes2:`country xcol update age:100 from codesSolution
t pj 1!codes2names country age employed digits
----------------------------------
Tom Ireland 110 1 "+353"
Mary England 113 0 "+44"
Jack France 114 1 "+33"
Sean England 118 1 "+44"
Anne Germany 121 0 "+49"
Roy Scotland 141 1 "+44"Explanation
pj (plus-join) behaves like a left join, except that for columns present in both tables it adds the right table's values to the left's instead of overwriting them. t's original age values (10, 13, 14, 18, 21, 41) are each increased by 100, the value from codes2, giving 110, 113, 114, 118, 121, 141. digits exists only in codes2, so it is simply added as a new column.
Be careful when both tables share a non-numeric column. If t already had a digits column (for example after running t:t lj 1!country xcol codesfrom the earlier question),pjwould try to add the two string columns together and fail with'type`. In that case, drop the column from the right table first: t pj 1!delete digits from codes2.