• blandry is correct, obviously data accuracy is the most important thing. Period. If a reports runs in seconds but has the wrong values it's useless. Even after accuracy is achieved, speed is not the be all and end all. But there is a limit. If you have a nightly process that takes an hour to run and you optimize it down to 15mins , well done but it doesnt really help anyone. If you have a routine that is fired by every user , every minute and that takes 10secs and you get it to run in 2, then that makes everyone more productive. Your system will be smoother and more predictable.

    These challenges are for 'fun' and education. You can learn a lot in what not to do as well what to do by just studying the code. And of course no-one can say that any particular query is the fastest possbile.

    Rules are limiting as solutions are sometimes art, rather than science, but here's my general quick list.

    Mostly pretty obvious

    Understand the data and understand the question and then understand what data is relevant to the answer.

    Minimize the amount of data io (Indexing and not re-reading tables)

    Minimize the amount of calculations

    Avoid Looping / RBAR



    Clear Sky SQL
    My Blog[/url]