Fish, like people, come from specific environments within their aquatic habitats. In the ocean, reefs are one habitat while rock caves are another. In freshwater, the water itself varies widely, along with the underwater terrain. The great Rift Lakes of Africa are known for their extremely alkaline, hard water and rocky environment, while the Amazon River has acidic, soft water filled with overflowing vegetation from its jungled banks. These entirely different environments are host to specific species of fish that have evolved and adapted to their surroundings.
Therefore, what type of fish to buy depends on what type of environment you have created in your aquarium. If your tank is already established and you are looking to add a fish, choose those whose native environment matches your tank's environment; one that will not get too big for your stocking capacity; and species that will get along well with your other fish. Be aware that different species occupy different levels of water. If you already have bottom dwellers like catfish, you might want a top dweller or mid-level dweller instead. Species also have specific temperaments, aggressive or peaceful, and are either nocturnal or diurnal.
Fortunately there are many ways to find out everything you need to know about any fish you might be considering. Aside from various atlases there are numerous online databases. Whether checking online or in print, be sure to cross-reference information about any specific species with at least 3 unrelated sources, and it's best not to use retailers as a source. They often use statistics that are overly forgiving and inaccurate, especially when it comes to how large a fish will grow. Instead, they often count on fish dying before ever reaching mature lengths. Therefore, beware of tankbuster species.
Fish are often cited as being able to adapt to a wide range of pH. In truth, most do not do well outside the pH of their native waters. Neon tetras are a perfect example. This brightly colored, peaceful freshwater schooling fish with its distinctive neon-blue and red stripe are commonly noted as being able to adjust to a pH ranging from acidic to alkaline. However, neon tetras kept in alkaline water live an average life span of 1-3 years. In their native Amazon environment where the water is soft and acidic they live an average of 20 years.
If you don't yet have an aquarium, consider if you are more interested in keeping a specific type of fish, or in creating a specific type of aquarium environment. If it's a species you are interested in, then research it first to make sure you can create its native habitat successfully. For tank mates, look for other species from that same environment that will be compatible in all the ways previously mentioned.
If it's a specific type of aquatic environment you want to create, then look for species native to that environment. For example, a heavily planted freshwater tank is akin to an acidic Amazonian, soft water environment perfect for peaceful schooling fish like neon tetras or the beautiful discus. Angelfish or gouramis will also do well, as will any acid-loving species. Just remember that large fish will eat small ones, so if you are going to have neon tetras or other small fish, avoid large species like angelfish.
Conversely, if you like the stark look of a freshwater sand and rock aquarium, this is akin to a Rift Lake environment which has very hard water and an alkaline pH. Aggressive cichlid fish will do well in this environment.
Before deciding on a specific freshwater environment, however, consider the nature of your tap water. If you have hard, alkaline water like most people, maintaining a soft water environment will be a lot of work and more expensive. If you need to make your water harder, that isn't as problematic. But it's easiest of all to keep species whose natural waters closely match the hardness and pH of your native tap.
When you take a fish home, make sure you know in advance what its needs are and that you can accommodate it for the duration of its life. Avoid walking down the aisle at the local pet store saying, "I'll take one of those, three of those, and that long one hiding behind the wood." Plan the population of your tank knowledgeably and you'll never be sorry.
Fish can live well over a decade. The investment is a long one, but filled with reward. Be good to your fish and they will be good to you, providing you with years of pleasure!