Almost all SELECT statements that join tables and use the join operator can be rewritten as subqueries, and vice versa. Writing the SELECT statement using the join operator is often easier to read and understand and can also help the Database Engine … [Read more...] about Should You Use Joins or Subqueries?
Queries
Derived Tables (Table expressions)
Table expressions are subqueries that are used where a table is expected. There are two types of table expressions: Derived tablesCommon table expressions A derived table is a table expression that appears in the FROM clause of a query. You can … [Read more...] about Derived Tables (Table expressions)
Common Table Expressions and Nonrecursive Queries
A common table expression (CTE) is a named table expression that is supported by Transact-SQL. There are two types of queries that use CTE: Nonrecursive queriesRecursive queries The following sections describe both query types. Note - Common … [Read more...] about Common Table Expressions and Nonrecursive Queries
Common Table Expressions and Recursive Queries
You can use CTEs to implement recursion because CTEs can contain references to themselves. The basic syntax for a CTE for recursive queries is WITH cte_name (column_list) AS (anchor_member UNION ALL recursive_member) outer_query cte_name and … [Read more...] about Common Table Expressions and Recursive Queries