For any database processing there will usually be several ways to achieve the same result. This page shows a series of tasks each with a couple of solutions, and explains why we consider one solution to be better than another.
There are a number of factors we use in judging which solution is better:
Surprisingly, we do see solutions that produce plausible but wrong answers. To be accepted, a candidate solution must work correctly in all real-world cases. That means we need tests to show that the solution is right.
The solution must be written so that we can understand it. If we can't understand it then we are "programming by coincidence". That is not good enough. We must know what we are doing and write our solution so that someone else can read it in a year from now and adapt it to work for what is needed then.
This means: