Summary

The simple SELECT command has a wealth of power and flexibility.

The key to understanding the SQL query is understanding that the query is declarative — you only phrase a question. The Query Optimizer determines how to execute the query, so SQL enables some flexibility in the development style of the query.

Following are a few of the key points from this chapter:

  • Think through the query in the logical flow of the query, not the syntax flow for the query.
  • The FROM clause can assemble data from ten different types of data sources. Think creatively about where you can find data for your query.
  • Never use SELECT *.
  • Aliases are a good thing, and always use the AS.
  • Be intentional about the WHERE clause. Use parentheses. Keep the expressions away from the source column.
  • Never trust the sort order to the physical order of the data on the disk. If the data needs to be sorted, then use an ORDER BY.

From this introduction, the next eight chapters incrementally add more advanced features that augment the power of SELECT: incorporating complex expressions, multiple types of joins, subqueries, and groupings.

Welcome to the set-based power of SQL.

Get Microsoft SQL Server 2012 Bible 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.