Slightly different from your approach, here I construct a new table by appending a column ("B") to ds
, where the value is looked up from ds2
via ID
:
lookup[x_] := Query[SelectFirst[#ID == x &], "B"]@ds2
SortBy["ID"]@ds[All, Append[#, "B" -> lookup[#ID]] &]