In the event a second mortgagee forecloses instead of a first mortgagee, the first mortgage remains intact and you receive the property subject to that first mortgage. So, you have to know when a bank forecloses whether they're first or second, but it is rare that a second lienholder forecloses.
If a homeowners' association forecloses, they are a special case. Normally the HOA lien is considered above the first mortgage, meaning it should wipe it out, but most HOA covenants provide that a mortgage is superior to a HOA lien. So, you have to check on these properties whether the HOA foreclosure comes with the first and second intact or wipes them out -- usually it comes with them attached.