Understanding best practices when querying data

To build fast queries, you need to follow some best practices when querying data. First, it's important to understand that you have to write the clauses in a specific order or your query will fail, as shown in the following list:

  • SELECT statement best practices:
  • Use SELECT fields instead of SELECT *. This is taxing on database resources, especially if a table has a lot of columns. It's best to write a query just to select the columns that you know you will need instead of selecting them all with SELECT *.
  • Use column aliases, especially when using functions. When you use a function in the WHERE clause, it will put the function as the name of the column instead of a more useful name. While giving ...

Get Learn SQL Database Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.