In a foreclosure proceeding the first mortgage holder has the senior or primary position when it comes to the sale of the property and the payment of sale proceeds. The second and any third or fourth, etc mortgage holders are junior to the first mortgage holder.
For example: The property has three mortgages on it. The first mortgage is for $100,000, the second is for $40,000 and the third is for $10,000. The house is put up for sale at the foreclosure auction, and it sells for $120,000 at the auction.
The first mortgage holder would recoup their entire investment first, so they would receive $100,000 as the senior or first mortgage holder. The second would receive the remaining $20,000, and would lose the other $20,000, and the third mortgage holder would be out their entire $10,000 and would receive nothing.
With foreclosure, there are no tax liabilities that I am aware of, since you are not being forgiven for any debt. It will go on your credit as a foreclosure. A short sale would allow for the forgiving of debt, which may incur tax liability, but a foreclosure does not. But a foreclosure will do more damage to your credit score.