Osmoregulation
Sea fish, for example, tend to gain salt if they live in seawater. So they actively put out (excrete) salt from their gills. River fish, on the other hand, take the salt out before they excrete water. Some fish, like the flounder, live in both fresh and salt water at different stages in its life. They adapt to whichever water they are in.