Water is a polar molecule, with one end positively charged, and the other negatively charged. These charges interact with ionic bonds in substances like table salt. The water molecules surround the charged particles in the salt with oppositely charged ends of the water molecules. This reduces the effective charges on the sodium and chlorine ions, so they no longer attract one another as much as they did before.
The rest of the work of dissolving the salt is done by heat and by the motion of the water, both of which jostle the ions apart, so they can be surrounded by water molecules and isolated.
The polar nature of water is also why non-polar molecules do not dissolve in water. Substances like oils, fats, and waxes have no charged parts to attract water molecules. The water molecules are attracted to one another by their charges, and they leave the non-polar molecules alone. This pulling together of all the water molecules acts to pull them away from uncharged molecules, so oil and water don’t mix.
Since water is denser than most oils, fats, and waxes, it falls to the bottom of the container, and the oil is left behind, on top.
Other materials, like metals, sand, rocks, or plastic, are also unaffected by water, and for the same reasons, only in reverse. The molecules in rocks and metals attract one another much more than they do water. So the metal atoms stick together and leave the water behind. Since they are generally heavier, they sink to the bottom, leaving the water on top.