You're forgetting that the stock of more than one company is traded.
So what a large chunk of the market ends up doing is buying index trackers or achieving the same goal by spreading investments as widely as possible.
I read somewhere there are actually more ETFs now than individual stocks.