@@ -708,9 +708,9 @@ Products[ProductPriceHistory, on = .(id = product_id), price := i.price]
708708
7097092 ) If we need to get the latest price and date (instead of all matches), we can still use := efficiently:
710710``` {r Updating with the Latest Record}
711- Products[ProductPriceHistory,
711+ Products[ProductPriceHistory,
712712 on = .(id = product_id),
713- `:=`(price = last(i.price), last_updated = last(i.date)),
713+ `:=`(price = last(i.price), last_updated = last(i.date)),
714714 by = .EACHI]
715715```
716716- last(i.price) ensures that only the latest price is selected.
@@ -720,10 +720,9 @@ Products[ProductPriceHistory,
7207203 ) When we need to update Products with multiple columns from ProductPriceHistory
721721``` {r Efficient Right Join Update }
722722cols <- setdiff(names(ProductPriceHistory), 'product_id')
723- Products[ProductPriceHistory,
724- on = .(id = product_id),
723+ Products[ProductPriceHistory,
724+ on = .(id = product_id),
725725 (cols) := mget(cols)]
726-
727726```
728727- Efficiently updates multiple columns in Products from ProductPriceHistory.
729728- mget(cols) retrieves multiple matching columns dynamically.
0 commit comments