The Amazing Dingo said:
Just to point this out, many villages and smaller communities had the habit of dumping their sewage downstream of the town. Of course, in towns and cities, this is impossible.
Safe drinking water is available from wells and from water cisterns set up to collect rain. Places like Rome and many desert cities would build aquaducts or underground canals to bring in their water from far away (the underground supply was hence safe from seige and such).
And if you are looking for a response to the disease problem, look to the Paladins and Clerics. Paladins of course have the Remove Disease ability. As zero-level spells, Clerics had Create Water and Purify Food & Drink. At higher levels they of course have a much larger supply of spells. This fact can help offset those diseases and problems. Of course, these depend on how magical a gaming world is.
Another idea is the use of magical monster to consume such wastes. There are several monsters out there that live off waste. Perhaps larger towns have captured such beasts and use them to consume their waste.
Or perhaps the creatures just shifted in there, or evolved to fit a niche. Most worlds are flooded with Ancient Civilisations Dead These Many Centuries, and so the city has probably been around a lot longer than our world (although I hasten to point out that irrigation and aquaportation have been around on a massive scale for thousands of years, as mentioned in the aqueducts above). The city, therefore, becomes a valid ecological location for creatures to evolve into and inhabit. Kinda like grass - people might import it, but it'll spring up on its own anyway, perhaps not as pretty as self-applied grass, perhaps with some nasty stuff growing in its midst, but it'll spring up anyway. (That's a metaphor that works on many levels.)
Many creates in the desert don't drink. Some collect moisture from the dew that forms on their body at night. Others stricky get their liquid from the creatures they kill.
These races could, over the years, have a natural tolerance of many of those minerals and foreign objects that would sicken you or I. Otherwise, I don't see why a large city on the surface can have a variety of wells and such to support them while Underdark cities can't have the same. Thats why these places are so rare - there has to be a source of water for any type of Underdark community to form. Similarly, perhaps they just open some type of portal to the Plane of Water with a variety of wards to keep those pesky creatures and elementals out. A Decantur of Endless Water only costs 9,000gp to buy or 9th level to create.
Also consider the possibility of elemental blood; there are a few rock monsters out there, and things that live in mineral-high environments are likely evolved populations with resistance to the more subtle threats of the region.
Dragons, of course, can eat anything and find it nourishing, it seems; the
draconis fundamentum, or whatever their specialised breath/digestion organ may be, is capable of breaking down just about anything short of artifact-level adamantite, so they can survive just eating sand for hundreds of years. Their biology, of course, is probably pretty strange because of this; I suspect there might be some fission and fusion involved, so they make their own water. They don't like it, of course, and would much rather eat something that can scream. And the same probably goes for a great number of other things; why should dragons be the only creatures with such an efficient digestive system? The remorhaz, for example, is clearly doing something it shouldn't.
There are insects and the like that can enter suspended animation states in the real world. It's possible that a more sophisticated lifeform could have the ability to go dormant and wake up when it smells prey nearby.
Back on the original question: Aqueducts, wells, and intelligent waste venting systems ("pour it in downstream, lads"). Plus a healthy dose of "eh, water's supposed to be brown, and I hear the plague's back in town" - Europeans are theorised to have developed excellent immune systems because of questionable living habits (mostly related to farm animals, I hear, but this could be another factor). Heck, 150 years ago any major metropolitan area (New York, London, Paris) could be counted on to stink of horse manure lying about in the streets, because horses were the only form of transport and the animals didn't use indoor plumbing... so my answer to "Where do cities find safe drinking water?" is "Partially they got it from sources other than the river, partially they didn't care".