Buildings can be quite complex when it comes to proper support, and each level needs to be held up to keep from crashing into the ground. Building up from the foundation is important, and thinking of support down from the roof to the foundation is essential. Any part of the structure above the foundation needs to be secured to it or to whatever it supports. Engineers spend a great deal of time ensuring buildings will not fall down or in, and it is their job to decide where support will be most useful.
The walls on top of the foundation are supported directly by it, but anything above them must depend upon its weight going through the walls to the foundation. A second level of any structure will have first floor walls that provide that support, and smaller buildings depend upon the outside walls for that function. If the ceiling, roof, or even a second story needs more support than the outer walls can handle, interior walls can also function as support.
Horizontal beams in ceilings are a good way to help support the upper story or the roof, but they can also be vertical in some structures. These are direct support beams, and they are often topped with horizontal beams to gather the weight onto the vertical beam. It might seem complex, but it is nothing more than a t-junction where the weight is concentrated in a small area. The size and structure of the vertical beam is a product of how much of the upper floors or roof it must support.
Many engineers and designers try to avoid vertical beams. While they function well, they can take up a great deal of area within a structure. Using stronger walls that would be incorporated in the structure anyway keeps more available floor space, and it is an important goal for many modern buildings.