My understand of medieval warfare was that sword fighting most mostly for personal defense and that actual battles between armies rarely used swords with spears being more common. Is this true? What weapons were most commonly used in battles besides the spear?
Unfortunately, the idea of a generic medieval battle is kind of impossible to answer. Warfare in the medieval period went through many changes, with many types of soldier with vastly different equipment.
Take the Early Medieval where you have the Byzantine which still seemed to use swords as a predominant side arm for some time. From what little we know of the Gothic and Vandal armies that took control of various sections of what was once the Western Roman Empire they also seemed to use swords with some frequency.
But by the end of the viking age, looking at depictions of battle such as the Bayeux Tapestry we see much less swords in battle. We see a lot of them worn when off the battlefield, but in the actual fighting spears and axes seem much more prominent. Not that there are no swords in the battle scenes, but not as many.
It's also important to know that at this time swords became something of a symbol of wealth. Many of the swords from this period where buried with the warrior that used them as a prized possession. From these burials we also get a glimpse at what was probably the most common side arm of the period: knives and daggers. Much cheaper and easier to make, and can be worn into battle even easier than a sword or axe. Slightly less common than the daggers and axes many mace heads have been found.
Once we get into the high medieval period, swords seem to have become a bit more common among those that could afford them. Development of arming swords ramped up. However, maces, axes, and daggers, were still very common likely far more common fighters who we have less developed records on. Uncovered battlegrounds certain show polearms definitely being the predominant weapon with spears, pikes, and billhooks. Warhammers, which seem to have been more of an oddity in the earlier periods start to be seen with some consistency. Those wealthy enough to have weaponsbearers would most certainly have swords with them. It was not uncommon for knights to have several weapons on their horses that they used including crossbows, swords, axes, maces, and daggers.
By the time we get to late medieval period we actually start to see a few types of warriors that predominantly used swords. From the famous doppelsoldner in the Landsknecht that used large two-handed swords to do... something against pike formations (jury’s still out if they were supposed to break pikes or just mess with them to disrupt the formation), to the very end of period where we see Spanish rondeleros using bucklers and sideswords to disrupt pike and shot lines. Swords also become mass produced, along with the rise of mercenary bands, we see the prestigious sword become very common as the price to make one dropped and more people making warfare their occupation. The previously mentioned Landsknecht even had a signature blade for the group called a katzbalger,
This is also the period where we see men-at-arms give a list of the types of weapons they used on their horses at what time. First use your lance, then once that isn't available take out your estoc (a type of thrusting sword), then you use your sword, then you use your axe, then your mace, and finally your dagger.
On foot, the various polearms would always be the primary weapon, for the heavily armored a pollaxe, what people today would probably call a warhammer (though often they were just also called pollaxes), but basically something big, two-handed, with a chance of dealing with an opponent that is also wearing armor. Something swords were never all that great at. And, of course, a dagger should basically always be on your person.