What are your most common SQL optimization that you used?
Couple of hints: Use
delete from table where id>=1 and id<=3;
instead of
delete from table where id=1;
delete from table where id=2;
delete from table where id=3;
Also use 'IN' instead of 'OR' syntax
My favorite list of tips (explained in detail here) is as follows
1) I've yet to find a situation where
SELECT Field1, Field2, (SELECT Count(*) FROM tblLinked WHERE tblLinked.Field3 = tblSource.Field3) AS TheTotal
FROM tblSource
isn't improved by a LEFT JOIN to a derived table.
SELECT Field1, Field2, IsNull(Linked.TheTotal,0) AS TheTotal
FROM tblSource
LEFT JOIN (SELECT Field3, Count(*) AS TheTotal
FROM tblLinked
GROUP BY Field3) AS Linked ON tblSource.Field3 = Linked.Field3
2) Don't sort the results on the server unless the consuming app is unable to do this itself. This applies less often to web apps, but for desktop apps the client PC usually has plenty of power available and can happily do a sort.
3) Use EXISTS instead of checking the Count of matching entries.
4) Don't get obsessed with doing a query in just one SELECT clause. Judicious use of table variables (and sometimes temporary tables) can massively reduce the rows processed.
Making sure tables are being joined in the correct order.
I have read all answers and I didn't found LIMIT and OFFSET usage hints. It is very common usage in pagination with "prev" and "next" links. But rendering such a display can consume more resources than the entire rest of the site. When offsetting large number items, query can become very slow. So avoid these queries.
Such methods uses Google, Twitter and other sites. In Google search there is no accurate number of results. There is only approximate number. Twitter doesn't allow user to view all past tweets. It shows only last n number (I can't remember how much).
There is some link from MySQL performance blog.