Try this code. Untested because I don't have your data, but the approach should work. I'm using get rows where instead of select where. Your biggest issue is that you're trying to set columns equal to each other. Instead you need to supply the row number as an index.
For( k =1, k <=N Row( selectedRows ), k++,
// Find the row in the ATE and Correlation tables that matches the serial number for the current row