Professional Documents
Culture Documents
Total of 68
Rows
Total of 69
Rows
4. Multiple Table Joins - Multiple types of joins
• Options:
• In a condition of the WHERE clause
• As a “table” of the FROM clause
• Within the HAVING clause
Join version
Same as:
Correlated vs. Noncorrelated Subqueries
• Noncorrelated subqueries:
• Do not depend on data from the outer query
• Execute once for the entire outer query
• Correlated subqueries:
• Make use of data from the outer query
• Execute once for each row of the outer query
• Can use the EXISTS operator
Processing a noncorrelated subquery
Same as:
Another Subquery Example
• Show all products whose standard price is higher than the average price
• We now use the subquery in the FROM clause
5 6
UNION EXAMPLE
• Find the cities in which you have either customers or suppliers:
First query
Combine
Second query
UNION – UNION ALL
• A more complicated example:
Note: With
UNION queries,
the quantity and
data types of the
attributes in the
SELECT clauses
of both queries
must be identical.
Conditional Expressions Using Case Syntax
• This is the way to build statements of the form: if … then …
Conditional Expressions Using Case Syntax
• When its results are correct, use that tested subset to test the outer
query…
• And if your query doesn’t run, learn how to read the errors…
• Examples on Joins
Example
Color Brand Car
Model
Find: The IDs and the colors of all the sports cars
Example
Color Brand Car
Model
Answer is 40!
Example
Color Brand Car
Model