Sometimes, this myth is in the form Goldfish only have a three second memory, and sometimes it is applied to all fish.
This Myth is nonsense. I suspect it was originated to justify keeping Goldfish in small bowls. The story was that by the time the Goldfish had finished swimming round the bare bowl, it had forgotten what it had seen and each short swim round was a journey of discovery.
Goldfish have a good memory for things that matter to them. Many people have done experiments about this. Over sixteen years ago, I did the following simple experiment. There was a pond in the front of our shop that has now been replaced by aquariums. I had one batch of goldfish that were staying near the bottom of the pond and were not easily visible. This is not good for selling the fish.
I decided to see how long it would take to train the Goldfish to come near the top when people came near. Each time I went close, I put a tiny amount of fish food on the water surface. The fish had learned before the end of the day and came up whenever anyone came near. They still remembered the next day.
My own experiment is also borne out by people's observations of the behaviour of fish in ponds. If you feed them occasionally, they come to the top. On the other hand, if a predator tries to catch the Goldfish, they hide near the bottom of the pond.
Recently, I saw on the television program Myth Busters a more complicated experiment that confirmed that Goldfish have good memories.