Neither is "better", but they are not perfectl interchangeable. For example, "we were at the beach" might mean that you were somewhere at a shorefront location. It might be a town, and you were on the boardwalk, or buying something in a shop, or eating in a restaurant nearby. It also could be used to refer to being in the water.
"On the beach" more strongly suggests you were actually on the sand that adjoins the water.
eat at a restaurant
Normally you would say:
eat at a restaurant.
This would imply that you went to the restaurant, were served food, and ate it.
If you were to say: eat in a restaurant
That would mean you ate food while inside the building.
Therefore,while both could be used, at implies being a customer, whereas in simply indicates location.
In work" means I have a job. I might not be there currently, but I have employment. "At work" means I am currently doing my job, or at least on the premises of my job.
'in school' is perhaps more common American English while 'at school' is more British but both are equally 'correct'. Similarly an American would probably say 'in college' while a Brit would say 'at university'.
Also , there is perhaps a slight subtle difference that 'in school' means they are in their school career - as opposed to having finished school, while 'at school' means they are there now.
So "are your children in school" = are they under 16 or 18 ? But "are your children at school" = are they at school today or are they at home.
(but that's from a BE perspective)
https://www.google.com/url?sa=t&source=web&rct=j&url=https://english.stackexchange.com/q/70849&ved=2ahUKEwj3396E97_mAhVM8BQKHbHTBJwQFjABegQIDRAH&usg=AOvVaw2wGfzePHJq8hDO3ar9aD12
https://www.google.com/url?sa=t&source=web&rct=j&url=https://www.espressoenglish.net/which-is-correct-at-school-or-in-school/&ved=2ahUKEwiJ4e6a-L_mAhWi6uAKHWoICy8QFjACegQIARAB&usg=AOvVaw3hXBZeyhqbFz0Z2ydpuU3C