merge(table1, table2[, c("pid", "val2")], by="pid")
Add in the all.x=TRUE argument in order to keep all of the pids in table1 that don't have matches in table2...
You were on the right track. Here's a way using match...
table1$val2 <- table2$val2[match(table1$pid, table2$pid)]