Select Statement Optimization
suggest changeA few habits shorten a SELECT:
- Index columns used in
WHEREon a large table.SELECT * FROM employee WHERE user_id > 2000can use an index onuser_id. Indexes also matter for joins. - When you need a few rows, use
LIMIT.SELECT * FROM employee LIMIT 20returns 20 rows, but withoutORDER BYit does not define which 20. - Name the columns you need.
SELECT id, name FROM employeemoves less data thanSELECT *when the table has many columns. - An index on
key_colcan speedSELECT * FROM tbl_name WHERE key_col IS NULL.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents