I want to be able to join two datasets by keys, pretty much like I'd do in SQL. I thought the JoinAcross function might do it, but it doesn't operate the way I thought. The example in the documentation shows:
JoinAcross[
{<|a -> 1, b -> X|>, <|a -> 2, b -> Y|>},
{<|a -> 1, c -> X|>, <|a -> 2, c -> Y|>}, Key[a]]
resulting in:
{<|a -> 1, b -> X, c -> X|>, <|a -> 2, b -> Y, c -> Y|>}
This joins down. What I need is like the following:
JoinAcross[
{<|a -> 1, b -> X|>, <|a -> 1, c -> Y|>},
{<|a -> 2, b -> XX|>, <|a -> 2, c -> YY|>}, Key[a]]
To give me:
{<|a->1, b->X, c->Y|>, <|a->2, b->XX, c->YY|>}
That's what I expect from a SQL join. Is there some way to do this with datasets, or should I go back to the "old way" of gathering things together?
Also, I really would like to do this by joining on 2 keys. Not just Key[a], but something like {Key[a],Key[b]}.





JoinAcrossis not like in SQL operation. I don't know an equivalent to your second operation in SQL. Have you not confused your key numbers in the second set? – Murta Aug 08 '14 at 10:46SELECT t1.ALOB, t2.ALOB, t1.EF1, t2.EF2 FROM [Factors] as t1 JOIN [Factors_OLD] as t2 on t1.ALOB=t2.ALOB
Where [Factors] and [Factors_OLD] are the 2 datasets. ALOB is the common column, "a" in the example. EF1 and EF2 are "b" and "c".
JoinAcross, in this case would seem to work within [Factors] and within [Factors_OLD], but would not join them together.
– Mitchell Kaplan Aug 08 '14 at 15:41JoinAcrosstakes two lists of associations. Each list of associations represents a SQL table. Your first example is exactly correct, because you're joining two tables by joining the rows that share a value for the key you're joining on. Your second example simply doesn't make sense from a SQL perspective, because both argument don't correspond to a table anymore -- the keys aren't the same anymore. You seem to be being confused by the fact that the linebreaking makes your two lists of associations 'line up' so the 1st (and 2nd) associations in each list resemble a table. – Taliesin Beynon Aug 08 '14 at 16:55