A system like in western countries, where you need a prescription from a doctor to purchase drugs in a 3rd party pharmacy, doesn’t exist in Thailand.
If a pharmacy has a certain drug they will sell it to you, no prescription required. There are certain controlled drugs, but regular pharmacies don’t have them, for these drugs you would have to see a doctor in a hospital and you would then get them from the hospital's pharmacy.