How SQL query results are generated

From the book – “SQL: The Complete Reference”

To generate the query results for a single-table SELECT statement, follow these steps:

// 1. FROM Clause:

Selecting the table or view containing data to be retrieved

// 2.  WHERE clause:

Selecting specific rows from the table.

If there is a WHERE clause, apply its search condition to each row of the table, retaining those rows for which the search condition is TRUE, and discarding those rows for which it is FALSE or NULL.

// 3. SELECT clause:

Generating the specific columns of query results and eliminating

duplicate rows, if requested.

For each remaining row, calculate the value of each item in the select list to produce a single row of query results. For each column reference, use the value of the column in the current row.

// 4. If SELECT DISTINCT is specified, eliminate any duplicate rows of query results that

were produced.

// 5.  ORDER BY clause:

If there is an ORDER BY clause, sort the query results as specified.

… The rows generated by this procedure comprise the query results.

Advertisement
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.