Fix selection when >1 optional layer activated

The bug was caused by the presence of more than 1 layer represented
by the same table. The system assumed there would be a 1:1 relationship
between layers and tables.

Also fixed the fact that the Potentially Selectable Set would contain
duplicate records if there was more than 1 layer based on a particular table.