Chapter 6

Introducing Basic Query Flow

In This Chapter

Using Understanding Query Flow

Using FROM Clause Data Source

Using WHERE conditions

Using Columns, Starts, Aliases, and Expressions

Ordering the Result Set

Using SELECT Distinct

Using TOP()

Structured Query Language (SQL), or more specifically Transact SQL (T-SQL) for SQL Server, is the romance language of data. Extracting or querying the single correct answer from gigabytes of relational data can seem overwhelming. This is until you master the logical flow of the query.

One of the first points to understand is that SQL is a declarative language. This means that the SQL query logically describes the question to the SQL Query Optimizer, which then determines the best method to physically execute the query. This method of execution is the query execution plan. As covered in the next eight chapters, you can often construct the query in many ways, but you can optimize each method to the same query execution plan. However, in some cases, queries that produce the same result set may use different execution plans. As a result, you can express the SQL query in the way that is most comprehensible and the easiest to maintain. In some cases, one method may be more efficient and faster than the other.

SQL queries aren't limited to the SELECT command. The four Data Manipulation Language (DML) commands, SELECT, INSERT, UPDATE, and DELETE, are sometimes taught as four separate and distinct commands. However, think of queries as a single ...

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.