The fish that swim next to sharks are called Pilot Fish.
Pilot Fish follow sharks and swim next to sharks as protection from other fish in the water that may eat them.
Those fish that would normally eat the Pilot Fish don't go near sharks because the Shark would eat those fish.
Pilot Fish are safe from being eaten by sharks because Pilot Fish eat the sharks parasites so the Pilot Fish are protected by the Sharks.