Some countries have many stock exchanges. What is the purpose of having multiple stock exchanges instead of consolidating all trading onto a single stock exchange? When there is only one stock exchange, all buyers and sellers meet at a single marketplace, which makes it easier to find willing buyers/sellers, facilitating price discovery. When there are multiple stock exchanges, buyers and sellers meet at many different marketplaces, which means that some mutually advantageous transactions do not take place because the buyer and seller were not aware of the trading opportunities offered by each other.
Consider times before the fast and efficient electronic communications. How would a trader from Chicago have an efficient access to an exchange in New York?
So historically many major cities had an exchange, some (like NYSE, LSE, etc) more popular than others (e.g.: Have you heard about the San Francisco stock exchange?). Over time, as communications and technology allowed for traders to easily access exchanges which were physically distant, the more popular ones started becoming the more prominent ones, with others merging into them (that same SF exchange ended up merging into NYSE eventually, after earlier mergers with other West-coast exchanges).
Some exchanges are specific to certain types of products (for example the Chicago Mercantile Exchange, or the Israeli diamond exchange), others target specific traders (for example Nasdaq, which has no physical trading floor. Its parent company owns several regional exchanges as well).
There are a variety of reasons why multiple stock exchanges came into existence:
I would say that the primary reason for the existence of multiple stock exchanges is that they are businesses started by investors, whether they be actual traders or businessmen. For example, the NYSE was begun by a group of investors circa 1800 who met under a buttonwood tree on Wall Street.
The AMEX was originally created as an alternative to the NYSE, but that role has been supplanted by NASDAQ.
Another reason would be advances in technology. The NASDAQ is an electronic computerized stock market which was established in the early 70s.
Many exchanges arose because regional location provided local access. Some regional exchanges arose because they focused on a specific market (mutual funds, options, lower quality stocks, etc.).
Another major reason differentiation. The NYSE has more stringent listing requirements compared to the NASDAQ which is more stringent than regional exchanges. At the bottom of the heap is the OTC BB.