Chapter 4: Combining Sets Flashcards
Does a Cross Join affect the logical query processing?
Yes, according to the main logical query processing, the FROM clause is evaluated first that the WHERE clause. But SQL Server Optimizer says let’s evaluate first the WHERE clause to filter the joined tables, and then let’s evaluate the FROM clause doing the MATCH in the ON clause.
What is a Inner Join?
Match rows from two tables based on a predicate, usally one that compares a primary key value in one side to a foreign key value in another side.
What is a Outer Join?
With outer joins, you can request to preserve all rows from one or both sides of the join, never
mind if there are matching rows in the other side based on the ON predicate.
What happens in a LEFT or RIGHT JOIN when doesn’t exist a match between two tables?
If it is a LEFT JOIN, the column values for the right table will be placeholded with NULL. In case of a RIGHT JOIN, the column values for the left table will be placeholded with NULL.
In a OUTER JOIN, what means a preserved side?
If we indicate a LEFT JOIN, the preserved side will be the left table, eg. “T1 LEFT JOIN T2”, T1 will be the preserved table. In a RIGHT JOIN, the preserved side will be the right table. Also, this means if the predicate which appears on the ON clause returns false or unknown with a specific row, the column values from the row of preserved side will be returned.
What is the principal difference between ON clause and the WHERE clause?
The ON clause just appear on the JOIN operations, so it is used for matching purpose. The WHERE clause is used for filtering purpose.
What is a FULL OUTER JOIN?
It’s a JOIN operation that preserves both tables.
A full outer join returns the inner rows that are normally returned from an inner join; plus
rows from the left that don’t have matches in the right, with NULLs used as placeholders in
the right side; plus rows from the right that don’t have matches in the left, with NULLs used as
placeholders in the left side.
What is the difference between the old and new syntax for cross joins?
The new syntax has the CROSS JOIN keywords between the table names and
the old syntax has a comma.
What are the different types of outer joins?
Left, right, and full.
What is a self contained subquery?
It’s a inner query that doesn’t depends to the outer query. It can runs independently.
What is a correlated subquery?
Correlated subqueries are subqueries where the inner query has a reference to a column from
the table in the outer query. They are trickier to work with compared to self-contained subqueries
because you can’t just highlight the inner portion and run it independently.
What is a table expression?
It is a named query.
What are the forms of table expressions?
(1) Derived tables.
(2) Common Table Expression (CTE).
(3) Views.
(4) Inline table-valued functions.
What is a derived table?
It is an inner query in the FROM clause. For example, SELECT * FROM (SELECT * FROM TABLE). The inner query is a derived table.
What is a Common Table Expression (CTE)?
A common table expression (CTE) is a similar concept to a derived table in the sense that it’s
a named table expression that is visible only to the statement that defines it. Like a query
against a derived table, a query against a CTE involves three main parts:
(1) The inner query.
(2) The name you assign to the query and its columns.
(3) The outer query.