These are the two single best paragraphs I've ever read on the topic of SQL optimization:
Query optimization is about computers doing less work at query time. Making your queries fast boils down to making your queries do less work for the same results. There are many different strategies for achieving that goal, and it takes technical knowledge to know which strategy to employ.
Doing less work means understanding 2 things: (a) know what your DB is doing, and (b) know how to adjust what you’re commanding the DB to do, to do less work.
This is a must-read if you write SQL. If you have teammates who write SQL, send this to them.Read more...