The fish that swim in schools do so primarily for protection. Although in some species, such as salmon, there is a sexual imperative component.
Larger marine mammals, particularly cetaceans of the whale, dolphin and porpoise species, swim together in pods because they are social animals. Smaller marine mammals such as seals, most species of penguin, and many of the fish species that inhabit upper- and mid-level waters swim in groups because doing so provides increased safety through three mechanisms.
The first of those is the well-known and accepted concept of “safety in numbers”. Their main natural predators are the larger carnivorous fish, including the multitude of shark species. These predators usually hunt seperately or in small groups. A fish on its own is a singular target, making it highly susceptible to being caught by such a predator. A fish in a group or school of several hundred increases its chances of not being the victim astronomically. The predator may still take a fish from the school, but the odds of being taken for an individual fish reduce from one in one to one in several hundred, clearly beneficial to the individual.
This principle is often seen in nature. Wildebeast cross crocodile infested rivers in their thousands for the same reason. Some are taken, but the vast majority cross safely because there are just too many for the crocodiles to take. Prey birds fly in flocks because raptors hunt singularly or in mated pairs, so again, the vast majority can travel unmolested.
The second reason schools are safer is from the number of eyes watching. Prey fish species have their eyes on the sides of their heads to give them a greater visual perspective, they can see more around them. By being in a group they benefit from the vision of those around them as well. The school can respond to the presense of a predator by moving with their conspecifics, even if the individual does not see the predator itself. This increases the ability of the school to avoid the predator so that no individual of the school is actually taken. It also increases the time they can focus on feeding, as part of the school they only have to watch out some of the time rather than always.
This is also seen frequently in nature. Terrestrial prey animals in a herd can spend more time grazing or browsing as the “watching for predators” is divided between the herd. Guard duty being shared. Flocks of birds do the same, taking flight together at the instigation of the watchers, rather than needing to see a predator themselves.
The third reason is more specific to fish. Scientific studies have determined that fish in schools are more “resistant” to predation. The fish swim together almost as though they are one animal. And that is quite a large animal. This seems to, at least sometimes, cause confusion for the predator. Where we might think that because there are so many fish in the school, a predator would be bound to get one, this is not the case. The larger the school, the less likely a predator will actually catch any fish at all.
Fish that spend most of their lives in the seas but swim upstream to headwaters to breed, like the salmon, swim together primarily because that allows greater choice in mates when they get there. But even this has a defensive component. They are predated on by terrestrial animals, such as grizzly bears. By all traveling upstream at the same time, the individuals chances of reaching the headwaters and procreating are greatly enhanced.
Unfortunately for fish, humankind are an evolutionary newcomer as a marine predator, and the current technologically advanced fisherman even more so. Less than a blink of the eye on an evolutionary timescale. Drift nets catch the whole school. Longlines catch those that don’t swim in schools and bottom trawling take the bottom-feeders that also don’t swim in schools. With no real or effective controls on the competing fishing nations in “international” waters, it is sadly no surprise that 70 percent of human-desired fish stocks are severely depleted.
The ecological destruction that such activities as longline fishing and bottom trawling do as a side-effect, hinders the ability of those uncaught to replenish their numbers. Being fewer, they also become more vulnerable to the predation of their natural predators. Evolving new behaviors in time to survive human predation is extremely unlikely, if we wish to continue eating fish we need to regulate our own activities urgently.