yes, in most cases you can buy whatever you want at pharmacies, but believe me, there are multiple pitfalls to getting back over the border with your purchases. I've seen mexican cops cuff and arrest people with prescription meds and vet steroids in their pockets. Its not for the inexperienced, but many people get away with it everyday.
For the more popular stuff, pain meds, anabolics, etc. There are fakes, but for the normal shit like antibiotics, erectile dysfunction meds, blood pressure, cholesterol, etc. Those will likely be legit unless its something that just came out, the market usually has some fakes until the generics in mexico compound it.