(This answer is based on the default setup of Ubuntu, with default repository preference)
If the same software has different versions, Apt will always try to use the most recent version of the software subject to dependency constraints.
*Please note that, Apt also look at the priority of a repository, if a higher priority of a repository has lower version, Apt won't upgrade the package. In default Ubuntu installation, all enabled repository has priority 500 except the backport repository, which has priority 100. So, if a software has higher versioned package in backport repository, that software will not be upgraded with
sudo apt-get install x command. You need to explicitly tell apt to use that repository by using command like this:
sudo apt-get install x/precise-backports. *
But, if two repo provide the same software with the same version, then Apt will install software from the repository which comes first in the
I'm quoting from apt_preference manual page:
Several instances of the same version of a package may be available
when the sources.list(5) file contains references to more than one
source. In this case apt-get downloads the instance listed earliest in
the sources.list(5) file. The APT preferences file does not affect the
choice of instance, only the choice of version.