Uploaded by Bijan Tavakoli

Week 10 Review Questions

advertisement
Week 10 Review Questions:
1. What is a correlated subquery? Give an example.
A correlated subquery is a subquery that executes once for each row in the outer query.
The process is similar to the typical nested loop in a programming language
2. Explain the difference between a regular subquery and a correlated subquery.
In a subquery the inner row executes first then the outer row then executes based off the
results from the inner query.
The query is called a correlated subquery because the inner query is related to the outer
query; the inner query references a column of the outer subquery.
3. What does it mean to say that SQL operators are set-oriented?
They operate over entire sets of rows and columns (tables) at once.
4. The relational set operators UNION, INTERSECT, and EXCEPT (MINUS) work properly
only when the relations are union-compatible. What does union-compatible mean, and
how would you check for this condition?
Union Compatible: Two or more tables that share the same number of columns and have
columns with compatible data types or domains. You would see if the 2 tables have same
attributes and that their data types are similar, doesn’t have to be same length if it is a
string but just that both of that certain attribute have to be strings.
5. What is the difference between UNION and UNIONALL? Write the syntax for each.
The UNION statement combines rows from two or more queries without including duplicate
rows.
UNION ALL query can be used to produce a relation that retains the duplicate rows. Therefore,
the following query will keep all rows from both queries (including the duplicate rows)
UNION Syntax:
SELECT column-list FROM T1
UNION
SELECT column-list FROM T2
UNION
SELECT column-list FROM T3
UNION
SELECT column-list FROM T4;
UNIONALL Syntax:
SELECT CUS_LNAME, CUS_FNAME, CUS_INITIAL, CUS_AREACODE, CUS_PHONE
FROM CUSTOMER
UNION ALL
SELECT CUS_LNAME, CUS_FNAME, CUS_INITIAL, CUS_AREACODE, CUS_PHONE
FROM CUSTOMER_2;
Download