If you're first and second is with the same lender, you have more leverage to work out a short sale, or to do a loan modification.
If your second is with a different lender, and you sell for enough to pay your first mortgage and some of your second, then your second lender may release your second mortgage if the excess funds go to them as collateral toward a new loan repayment plan. The first mortgage lender doesn't really give a rip about your second as long as they can get their money in the sale. But if the second lender refuses to release your mortgage, then you either keep the notes current while you try to sell for enough for both, or talk to your first lender about doing a short sale due to your hardship of not affording to make payments on your home.
It will all come down to how you present your case, but lenders need to know you have a legitimate reason for needing to sell short. This is likely your best opportunity for getting the second released because they know that in a short sale, they will receive at least some money, vs NOTHING if the first lender or whoever pays off the first forecloses off the junior lien holders. We always get a CMA done for our clients, and make sure that we have an opportunity to present the CMA and repairs needed as part of the BPO process for a short sale.
If you need specific help or guidance with a short sale or other options....email firstname.lastname@example.org
As the previous posters stated you would be facing a "short sale", where your lender/bank would have to approve the sale at a price less then the mortgage.
There are many posts on the short-sale process but the condensed version is that when you get an offer on your home, it is submitted to your lender/bank for review/approval/counter offer. This stage is notorious for taking a lengthy period of time to complete but some banks move faster than others.
As Dot mentioned there are also tax implications depending on your specific situation. You may have to pay income taxes on the difference of what you owe on the mortgage vs. what you sell it for, so as others mentioned you should contact an accountant or real estate attorney for further information.
In a short sale your lender(s) have to approve the sale because they have to agree to take less money. You also should consult your CPA to see if there will be any tax ramifications you need to be aware of.
Best of luck to you!