To understand how these three are interrelated, you have to take a look at how the American Southwest was different in the mid-1800's. Mexico owned a good chunk of the territory there, including what we now call the states of Texas, Nevada, California, New Mexico, and Arizona. There weren't a whole lot of folks there, though.
Comanche indians were proving troublesome to the Mexican government in the area, and Mexico decided to induce American settlers to the area to act as a "buffer" between the areas where Mexicans lived and the raiding natives. It looked like a big win to them...the Americans would improve the land and pay taxes, while also keeping the tribes at bay.
The problem was that the American settlers didn't want to settle in the areas designated as a "buffer," but rather wanted to go where the land was fertile and they could make a living (surprise surprise.) They also brought with them their slaves, something the Mexican government didn't allow. Eventually, settlers in these areas greatly outnumbered the Mexicans living there, and the settlers pulled further and further away from their control. The Mexican government attempted to limit immigration and outlaw slavery, but the Texans ignored them. Eventually, the Mexican government (led by dictator Santa Anna) attempted to use force to subdue the setters in Texas and force them to accept Mexican domination. After a victory (of sorts) at the Alamo, Santa Anna and his army was defeated and the dictator was forced to allow Texas to form its own republic.
Still, this wasn't the Mexican war.
Despite the peace treaty with Texas, Mexico refused to recognize the new republic as legitimate. Instead, Texas was considered a territory that was in rebellion and that would eventually be subdued. For a while, things remained in a balance. The Mexican government could not feasibly invade Texas and the United States did not attempt to annex the nation for itself (despite Texas' desire for it to do so.)
Americans were unsure about what to do with Texas. Northern states were opposed to allowing Texas into the Union because it would enter as a slave-holding state, thus upsetting the delicate balance of power. Others knew that annexing Texas would almost certainly start a war with Mexico, which they didn't want. It took almost 10 years after its declaration of independence from Mexico for Texas to become part of the United States, and sure enough, trouble started right away.
While the annexation didn't lead to immediate war, it increased tensions in the region until the Mexican government chose to flex its muscle and send military forces to the region. This was all the excuse the United States needed to send in its own military, and thus the Mexican War was started.