Select Statement Optimization

suggest change

A few habits shorten a SELECT:

  1. Index columns used in WHERE on a large table. SELECT * FROM employee WHERE user_id > 2000 can use an index on user_id. Indexes also matter for joins.
  2. When you need a few rows, use LIMIT. SELECT * FROM employee LIMIT 20 returns 20 rows, but without ORDER BY it does not define which 20.
  3. Name the columns you need. SELECT id, name FROM employee moves less data than SELECT * when the table has many columns.
  4. An index on key_col can speed SELECT * FROM tbl_name WHERE key_col IS NULL.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents